💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Fix OpenAI chat message selection
FU-max-boop01b456900a9e
diff --git a/src/python/txtai/api/routers/openai.py b/src/python/txtai/api/routers/openai.pyindex 0a793ce1..1b19291a 100644--- a/src/python/txtai/api/routers/openai.py+++ b/src/python/txtai/api/routers/openai.py@@ -44,8 +44,8 @@ def chat(# Build keyword argumentskwargs = {key: value for key, value in [("stream", stream), ("maxlength", max_completion_tokens)] if value}- # Get first message- message = messages[0]["content"]+ # Get latest message+ message = messages[-1]["content"]# Agentif model in application.get().agents:diff --git a/test/python/testapi/testopenai.py b/test/python/testapi/testopenai.pyindex 0fba6d40..6fe54276 100644--- a/test/python/testapi/testopenai.py+++ b/test/python/testapi/testopenai.py@@ -122,6 +122,24 @@ class TestOpenAI(unittest.TestCase):self.assertIsNotNone(response["choices"][0]["message"]["content"])+ def testChatLatestMessage(self):+ """+ Test a chat completion with multiple messages+ """++ response = self.client.post(+ "/v1/chat/completions",+ json={+ "messages": [+ {"role": "system", "content": "You are a helpful assistant"},+ {"role": "user", "content": "Hello"},+ ],+ "model": "segmentation",+ },+ ).json()++ self.assertEqual(response["choices"][0]["message"]["content"], "Hello")+def testChatPipeline(self):"""Test a chat completion with a pipeline