togethercomputer / together-python

The Official Python Client for Together's API
https://pypi.org/project/together/
Apache License 2.0
21 stars 4 forks source link

Tool/Function response messages with role='tool' not accepted #113

Closed marklysze closed 3 months ago

marklysze commented 3 months ago

Describe the bug I tried running the function calling code from the website...

https://docs.together.ai/docs/function-calling#multi-turn-example

... but using the Together.AI Python library and it was successful in selecting a function and providing arguments, however if I feed the result of the function call back to try and get another response it throws an exception that it doesn't accept the role='tool' in the message.

Failing Line:

function_enriched_response = client.chat.completions.create(
        model="mistralai/Mixtral-8x7B-Instruct-v0.1",
        messages=messages,

Exception thrown:

1 validation error for ChatCompletionRequest messages.
2.role
  Input should be 'assistant', 'system' or 'user' [type=enum, input_value='tool', input_type=str]

To Reproduce

  1. Use the multi-turn example code here: https://docs.together.ai/docs/function-calling#multi-turn-example

  2. Replace:

    client = openai.OpenAI(
    base_url = "https://api.together.xyz/v1",
    api_key = os.environ['TOGETHER_API_KEY'],
    )

    with client = Together(api_key=os.environ.get("TOGETHER_API_KEY"))

  3. Run it

Expected behaviour No exception is throw and the response is processed by the LLM and a response is returned.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

orangetin commented 3 months ago

thanks for the detailed report @marklysze ! The fix has been pushed with v1.1.3

marklysze commented 3 months ago

Perfect, thanks @orangetin!