toolhouseai / toolhouse-sdk-python

Apache License 2.0
15 stars 2 forks source link

Sample Code Error #5

Open khiryshank opened 3 months ago

khiryshank commented 3 months ago

I believe there's a bug in the sample code.

import os
from dotenv import load_dotenv
from toolhouse import Toolhouse
from openai import OpenAI
from typing import List

load_dotenv()

client = OpenAI()
tools = Toolhouse()

#Metadata to convert UTC time to your localtime
th.set_metadata("timezone", -7)

messages: List = [{
    "role": "user",
    "content": "What's the current time?"
}]

response = client.chat.completions.create(
    model='gpt-4o',
    messages=messages,
    tools=tools.get_tools(),
    tool_choice="auto"
)

messages += th.run_tools(response)

response = client.chat.completions.create(
            model="gpt-4o-mini",
            messages=messages,
            tools=tools.get_tools(),
            tool_choice="auto"
        )
print(response.choices[0].message.content)

This produces the error: th.set_metadata("timezone", -7) ^^ NameError: name 'th' is not defined

However, this should fix it

import os
from dotenv import load_dotenv
from toolhouse import Toolhouse
from openai import OpenAI
from typing import List

load_dotenv()
TH_TOKEN = os.getenv("TOOLHOUSE_BEARER_TOKEN")
client = OpenAI()
tools = Toolhouse()
th = Toolhouse(access_token=TH_TOKEN, provider="openai")
#Metadata to convert UTC time to your localtime
th.set_metadata("timezone", -7)

messages: List = [{
    "role": "user",
    "content": "What's the current time?"
}]

response = client.chat.completions.create(
    model='gpt-4o',
    messages=messages,
    tools=tools.get_tools(),
    tool_choice="auto"
)

messages += th.run_tools(response)

response = client.chat.completions.create(
            model="gpt-4o-mini",
            messages=messages,
            tools=tools.get_tools(),
            tool_choice="auto"
        )
print(response.choices[0].message.content)
aaishikasb commented 4 days ago

Hey @khiryshank, thanks for pointing this out! Will fix it in an upcoming PR!