Skip to content

Commit 10dea59

Browse files
committed
Add localai to text_chat
1 parent d27146b commit 10dea59

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

processors/providers/promptly/text_chat.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class TextChatConfiguration(ApiProcessorSchema):
7575
use_azure_if_available: bool = Field(
7676
title='Use Azure if available', default=True, description='Use Azure if available. Will fallback to OpenAI when unchecked', advanced_parameter=True,
7777
)
78+
use_localai_if_available: bool = Field(
79+
title='Use LocalAI if available', default=False, description='Use LocalAI if available. Will fallback to OpenAI or Azure OpenAI when unchecked', advanced_parameter=True,
80+
)
7881
chat_history_in_doc_search: int = Field(
7982
title='Chat history in doc search', default=0, description='Number of messages from chat history to include in doc search', advanced_parameter=True,
8083
)
@@ -235,7 +238,18 @@ def process(self) -> dict:
235238
temperature=self._config.temperature,
236239
stream=True,
237240
)
241+
elif self._env['localai_api_key'] and self._env['localai_base_url'] and self._config.use_localai_if_available:
242+
openai.api_key = self._env['localai_api_key']
243+
openai.api_base = self._env['localai_base_url']
244+
model = self._config.dict().get('model', 'gpt-3.5-turbo')
238245

246+
result = openai.ChatCompletion.create(
247+
model=model,
248+
messages=[system_message] +
249+
[context_message] + self._chat_history,
250+
temperature=self._config.temperature,
251+
stream=True,
252+
)
239253
elif self._env['openai_api_key'] is not None:
240254
openai.api_key = self._env['openai_api_key']
241255
model = self._config.dict().get('model', 'gpt-3.5-turbo')

0 commit comments

Comments
 (0)