Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add FunctionMessage support to _convert_dict_to_message() in OpenAI chat model #6382

Conversation

thehunmonkgroup
Copy link
Contributor

Already supported in the reverse operation in _convert_message_to_dict(), this just provides parity.

@hwchase17
@agola11

@vercel
Copy link

vercel bot commented Jun 18, 2023

@thehunmonkgroup is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wont we want to include additional_kwargs?

Can we add unit test?

@thehunmonkgroup
Copy link
Contributor Author

wont we want to include additional_kwargs?

@hwchase17 none of the other elements of that function add additional_kwargs besides the function_call in the AIMessage conversion. It's not clear to me what we would even add to additional_kwargs in the FunctionMessage case.

Here's the example code from OpenAI, looks like passing a function message is just the role, name, and content to me:

{
  "model": "gpt-3.5-turbo-0613",
  "messages": [
    {"role": "user", "content": "What is the weather like in Boston?"},
    {"role": "assistant", "content": null, "function_call": {"name": "get_current_weather", "arguments": "{ \"location\": \"Boston, MA\"}"}},
    {"role": "function", "name": "get_current_weather", "content": "{\"temperature\": "22", \"unit\": \"celsius\", \"description\": \"Sunny\"}"}
  ],
  "functions": [
    {
      "name": "get_current_weather",
      "description": "Get the current weather in a given location",
      "parameters": {
        "type": "object",
        "properties": {
          "location": {
            "type": "string",
            "description": "The city and state, e.g. San Francisco, CA"
          },
          "unit": {
            "type": "string",
            "enum": ["celsius", "fahrenheit"]
          }
        },
        "required": ["location"]
      }
    }
  ]
}

If you could confirm that the existing code is correct, I'll try to work up a unit test, first time contributor, so I'll need to fumble my way through it ;)

Already supported in the reverse operation in _convert_message_to_dict(),
this just provides parity.
@thehunmonkgroup thehunmonkgroup force-pushed the function-message-for-dict-to-message branch from 0b1128b to 38de053 Compare June 19, 2023 01:24
@thehunmonkgroup
Copy link
Contributor Author

Can we add unit test?

@hwchase17 well there wasn't even a unit test file for chat_models/test_openai.py ;)

I think I got a correct test written and it's passing.

Let me know if you need anything else to get this PR in.

@hwchase17
Copy link
Contributor

wont we want to include additional_kwargs?

@hwchase17 none of the other elements of that function add additional_kwargs besides the function_call in the AIMessage conversion. It's not clear to me what we would even add to additional_kwargs in the FunctionMessage case.

Here's the example code from OpenAI, looks like passing a function message is just the role, name, and content to me:

{
  "model": "gpt-3.5-turbo-0613",
  "messages": [
    {"role": "user", "content": "What is the weather like in Boston?"},
    {"role": "assistant", "content": null, "function_call": {"name": "get_current_weather", "arguments": "{ \"location\": \"Boston, MA\"}"}},
    {"role": "function", "name": "get_current_weather", "content": "{\"temperature\": "22", \"unit\": \"celsius\", \"description\": \"Sunny\"}"}
  ],
  "functions": [
    {
      "name": "get_current_weather",
      "description": "Get the current weather in a given location",
      "parameters": {
        "type": "object",
        "properties": {
          "location": {
            "type": "string",
            "description": "The city and state, e.g. San Francisco, CA"
          },
          "unit": {
            "type": "string",
            "enum": ["celsius", "fahrenheit"]
          }
        },
        "required": ["location"]
      }
    }
  ]
}

If you could confirm that the existing code is correct, I'll try to work up a unit test, first time contributor, so I'll need to fumble my way through it ;)

ah right sorry, got confused

thanks!

@hwchase17 hwchase17 added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Jun 20, 2023
@dev2049 dev2049 merged commit 10adec5 into langchain-ai:master Jun 20, 2023
tconkling added a commit to tconkling/langchain that referenced this pull request Jun 20, 2023
* master: (101 commits)
  add FunctionMessage support to `_convert_dict_to_message()` in OpenAI chat model (langchain-ai#6382)
  bump version to 206 (langchain-ai#6465)
  fix neo4j schema query (langchain-ai#6381)
  Update serpapi.py Support baidu list type answer_box (langchain-ai#6386)
  fix: llm caching for replicate (langchain-ai#6396)
  feat: use latest duckduckgo_search API to call (langchain-ai#6409)
  Harrison/unstructured page number (langchain-ai#6464)
  Improve error message (langchain-ai#6275)
  Fix the issue where ANTHROPIC_API_URL set in environment is not takin… (langchain-ai#6400)
  Fix broken links in autonomous agents docs (langchain-ai#6398)
  Update SinglStoreDB vectorstore (langchain-ai#6423)
  Fix for langchain-ai#6431 - chatprompt template with partial variables giing validation error (langchain-ai#6456)
  Harrison/functions in retrieval (langchain-ai#6463)
  Incorrect argument count handling (langchain-ai#5543)
  Fixed a link typo /-/route -> /-/routes. and change endpoint format (langchain-ai#6186)
  docs `retrievers` fixes (langchain-ai#6299)
  Update introduction.mdx (langchain-ai#6425)
  Fix Custom LLM Agent example (langchain-ai#6429)
  Remove backticks without clear purpose from docs (langchain-ai#6442)
  Update web_base.ipynb (langchain-ai#6430)
  ...
bdonkey added a commit to bdonkey/langchain that referenced this pull request Jun 20, 2023
* master: (158 commits)
  Fix link (langchain-ai#6501)
  docs/fix links (langchain-ai#6498)
  Update notebook for MD header splitter and create new cookbook (langchain-ai#6399)
  Vector store support for Cassandra (langchain-ai#6426)
  improve documentation on base chain (langchain-ai#6468)
  fix: change ddg to DDGS (langchain-ai#6480)
  release 207 (langchain-ai#6488)
  Add Alibaba Cloud OpenSearch as a new vector store (langchain-ai#6154)
  fix openai qa chain (langchain-ai#6487)
  add FunctionMessage support to `_convert_dict_to_message()` in OpenAI chat model (langchain-ai#6382)
  bump version to 206 (langchain-ai#6465)
  fix neo4j schema query (langchain-ai#6381)
  Update serpapi.py Support baidu list type answer_box (langchain-ai#6386)
  fix: llm caching for replicate (langchain-ai#6396)
  feat: use latest duckduckgo_search API to call (langchain-ai#6409)
  Harrison/unstructured page number (langchain-ai#6464)
  Improve error message (langchain-ai#6275)
  Fix the issue where ANTHROPIC_API_URL set in environment is not takin… (langchain-ai#6400)
  Fix broken links in autonomous agents docs (langchain-ai#6398)
  Update SinglStoreDB vectorstore (langchain-ai#6423)
  ...
This was referenced Jun 25, 2023
@thehunmonkgroup thehunmonkgroup deleted the function-message-for-dict-to-message branch July 1, 2023 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm PR looks good. Use to confirm that a PR is ready for merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants