88from langchain_core .messages import BaseMessage
99from requests import Timeout
1010
11+ from danswer .configs .model_configs import GEN_AI_ACCOUNT_ID
1112from danswer .configs .model_configs import GEN_AI_API_VERSION
1213from danswer .configs .model_configs import GEN_AI_CLIENT_ID
1314from danswer .configs .model_configs import GEN_AI_CLIENT_SECRET
1415from danswer .configs .model_configs import GEN_AI_IDENTITY_ENDPOINT
1516from danswer .configs .model_configs import GEN_AI_MAX_OUTPUT_TOKENS
17+ from danswer .configs .model_configs import GEN_AI_TENANT_ID
1618from danswer .llm .interfaces import LLM
1719from danswer .llm .interfaces import LLMConfig
1820from danswer .llm .interfaces import ToolChoiceOptions
@@ -66,10 +68,12 @@ def __init__(
6668 api_key : str | None ,
6769 timeout : int ,
6870 endpoint : str
69- | None = "https://alpha.uipath.com/llmgateway_/openai/deployments /gpt-4o-mini- 2024-07-18/chat/ completions?api-version=2024-06-01 " ,
71+ | None = "https://alpha.uipath.com/{account_id}/{tenant_id}/ llmgateway_/api/raw/vendor/ openai/model /gpt-4o-2024-11-20/ completions" ,
7072 identity_url : str | None = GEN_AI_IDENTITY_ENDPOINT ,
7173 client_id : str | None = GEN_AI_CLIENT_ID ,
7274 client_secret : str | None = GEN_AI_CLIENT_SECRET ,
75+ account_id : str | None = GEN_AI_ACCOUNT_ID ,
76+ tenant_id : str | None = GEN_AI_TENANT_ID ,
7377 max_output_tokens : int = int (GEN_AI_MAX_OUTPUT_TOKENS ),
7478 api_version : str | None = GEN_AI_API_VERSION ,
7579 ):
@@ -97,6 +101,18 @@ def __init__(
97101 "client_secret for the model server."
98102 )
99103
104+ if not account_id :
105+ raise ValueError (
106+ "Cannot point Danswer to a custom LLM server without providing the "
107+ "account_id (GEN_AI_ACCOUNT_ID) for the model server."
108+ )
109+
110+ if not tenant_id :
111+ raise ValueError (
112+ "Cannot point Danswer to a custom LLM server without providing the "
113+ "tenant_id (GEN_AI_TENANT_ID) for the model server."
114+ )
115+
100116 # TODO: implement api versions for endpoints and add those to model
101117 # if not api_version:
102118 # raise ValueError(
@@ -107,7 +123,9 @@ def __init__(
107123 self ._identity_url = identity_url
108124 self ._client_id = client_id
109125 self ._client_secret = client_secret
110- self ._endpoint = endpoint
126+ self ._account_id = account_id
127+ self ._tenant_id = tenant_id
128+ self ._endpoint = endpoint .format (account_id = account_id , tenant_id = tenant_id )
111129 self ._max_output_tokens = max_output_tokens
112130 self ._timeout = timeout
113131 self .token = self ._get_token ()
@@ -123,11 +141,13 @@ def __init__(
123141 def _execute (self , input : LanguageModelInput ) -> AIMessage :
124142 headers = {
125143 "Content-Type" : "application/json" ,
126- "X-UiPath-LlmGateway-RequestedFeature" : "ChatWithAssistant" ,
127- "X-UiPath-LlmGateway-RequestingFeature" : "ChatWithAssistant" ,
144+ "Authorization" : "Bearer " + self .token ,
128145 "X-UiPath-LlmGateway-RequestingProduct" : "darwin" ,
146+ "X-UiPath-LlmGateway-RequestingFeature" : "ChatWithAssistant" ,
147+ "X-UiPath-LlmGateway-ApiFlavor" : "chat-completions" ,
148+ "X-UiPath-LlmGateway-ApiVersion" : "2024-10-21" ,
129149 "X-UiPath-LlmGateway-TimeoutSeconds" : "60" ,
130- "Authorization " : "Bearer " + self . token ,
150+ "X-UIPATH-STREAMING-ENABLED " : "false" ,
131151 }
132152
133153 # print(f"Input: {input}")
@@ -226,4 +246,6 @@ def config(self) -> LLMConfig:
226246 model_name = self ._model_version ,
227247 temperature = self ._temperature ,
228248 api_key = self ._api_key ,
249+ api_base = self ._endpoint ,
250+ api_version = None ,
229251 )
0 commit comments