Skip to content

Commit

Permalink
Fixing response content handling on groq and openai
Browse files Browse the repository at this point in the history
  • Loading branch information
Getty committed Jan 12, 2025
1 parent bfdee45 commit ea247e7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "tackleberry"
version = "0.1.0"
version = "0.1.1"
description = "Tackleberry (or TB) is helping you tackle the access to AI"
authors = [
{ name = "Torsten Raudßus", email = "[email protected]" },
Expand Down
2 changes: 1 addition & 1 deletion tackleberry/runtime/groq.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def chat_context(self, chat: TBChat, context: TBContext, struct: BaseModel = Non
model=chat.model.name,
messages=self.get_messages_from_context(context),
)
return response.content
return response.choices[0].message.content

def __str__(self):
return f"TB Runtime Groq {hex(id(self))}"
2 changes: 1 addition & 1 deletion tackleberry/runtime/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def chat_context(self, chat: TBChat, context: TBContext, struct: BaseModel = Non
model=chat.model.name,
messages=self.get_messages_from_context(context),
)
return response.content
return response.choices[0].message.content

def __str__(self):
return f"TB Runtime OpenAI {hex(id(self))}"
46 changes: 46 additions & 0 deletions tests/test_110_standard_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import unittest
import warnings
import os
from unittest.mock import patch
import requests
from tackleberry import TB

import sys

class TestTB(unittest.TestCase):

def test_010_openai(self):
"""Test OpenAI"""
if os.environ.get("OPENAI_API_KEY"):
chat = TB.chat('openai/gpt-4o-mini')
test_resp = chat.query("Say test")
else:
warnings.warn("Can't test OpenAI runtime without OPENAI_API_KEY", UserWarning)

def test_020_anthropic(self):
"""Test Anthropic"""
if os.environ.get("ANTHROPIC_API_KEY"):
chat = TB.chat('anthropic/claude-3-5-haiku-20241022')
test_resp = chat.query("Say test")
else:
warnings.warn("Can't test Anthropic runtime without ANTHROPIC_API_KEY", UserWarning)

def test_030_groq(self):
"""Test Groq"""
if os.environ.get("GROQ_API_KEY"):
chat = TB.chat('groq/llama3-8b-8192')
test_resp = chat.query("Say test")
else:
warnings.warn("Can't test Groq runtime without GROQ_API_KEY", UserWarning)

def test_040_ollama(self):
"""Test Ollama"""
ollama_model = os.environ.get("TACKLEBERRY_OLLAMA_TEST_MODEL") or 'gemma2:2b'
if (os.environ.get("OLLAMA_HOST") or os.environ.get("OLLAMA_PROXY_URL")) and ollama_model:
chat = TB.chat('ollama/'+ollama_model)
test_resp = chat.query("Say test")
else:
warnings.warn("Can't test Ollama runtime without explicit setting OLLAMA_HOST or OLLAMA_PROXY_URL", UserWarning)

if __name__ == "__main__":
unittest.main()

0 comments on commit ea247e7

Please sign in to comment.