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

Agent tool support #134

Merged
merged 7 commits into from
Mar 26, 2024
Merged

Conversation

xuechendi
Copy link
Contributor

Support for openAI format tools and tool_choice
Request:

client.chat.completions.create(
  model=“mistral-7b",
  messages=messages,
  tools=tools,
  tool_choice="auto"
)

Reply:

{ 'role': 'assistant’, 
  'content': None, 'function_call': None, 
  'tool_calls': [{
     'id': 'call_xxxxxx’, 'type': 'function’,
     'function': {'arguments': ‘{“arg1": “..", “arg2": “.."}’, 'name’: {custom_func_name}},
}]}

Example screen shot:
image

Example used codes:

tools = [GetCurrentWeatherTool()]
prompt = hub.pull(args.prompt_template)
llm = ChatOpenAI(
    openai_api_base=openai_base_url,
    model_name=args.model_name,
    openai_api_key=openai_api_key,
    max_tokens=args.max_tokens,
    callbacks=[
        StreamingStdOutCallbackHandler() if args.streaming_response else StdOutCallbackHandler()
    ],
    streaming=args.streaming_response,
)
agent = create_openai_tools_agent(tools=tools, llm=llm, prompt=prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
agent_executor.invoke({"input": "what is the weather today in Boston?"})

@xuechendi
Copy link
Contributor Author

@carsonwang , this is initial PR to support tool calls.
The reference vLLM PR is closed not merged. This pr is following both RayLLM and vLLM.

cheehook pushed a commit to JoshuaL3000/llm-on-ray that referenced this pull request Mar 8, 2024
* initial version

* update path & support pdf uploader

* update

* update

* update

* update

* update

* update

* update memory

* upd after testing on spr
@xuechendi xuechendi force-pushed the agent_tool_support_clean_prompt branch 3 times, most recently from 3a0e574 to ff0b577 Compare March 11, 2024 17:21
@xuechendi
Copy link
Contributor Author

@carsonwang , please help to review, and BTW, can you point me some one to check the right steps for adding CI functions.

@xuechendi
Copy link
Contributor Author

Hello, @carsonwang and @jiafuzha, I'll only add http based query test in this PR. And add my langgchain/openai CI in a separate PR including both agent tool and MLLM tests.

@xuechendi
Copy link
Contributor Author

@carsonwang , CI is added. This PR is ready for review.

@carsonwang
Copy link
Contributor

@xuechendi , this is great! I will look into it.

@xuechendi
Copy link
Contributor Author

@carsonwang , follow up on this PR, any comments?

@@ -1713,6 +1718,12 @@ def _init_ui(self):
type=str,
help="The ip:port of head node to connect when restart a worker node.",
)
parser.add_argument(
"--ref_app_url",
default="http://127.0.0.1:8501",
Copy link
Contributor

Choose a reason for hiding this comment

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

How can other external users make this work by default? can you please add document how to launch it? If not, can you please remove and add an option to make it work for you only for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I removed this update

TARGET=${{steps.target.outputs.target}}
if [[ ${{ matrix.model }} == "mistral-7b-v0.1" ]]; then
docker exec "${TARGET}" bash -c "llm_on_ray-serve --models ${{ matrix.model }}"
docker exec "${TARGET}" bash -c "python examples/inference/api_server_openai/query_http_requests_tool.py --model_name ${{ matrix.model }}"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is to run the example, can we test and verify the LLM response is a correct Json to call the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

UT verification added, only test on function name, using llama to inference

@xuechendi xuechendi force-pushed the agent_tool_support_clean_prompt branch 3 times, most recently from 70e801f to f9d1287 Compare March 25, 2024 14:13
xuechendi and others added 7 commits March 25, 2024 22:12
Signed-off-by: Xue, Chendi <chendi.xue@intel.com>
Signed-off-by: Xue, Chendi <chendi.xue@intel.com>
Signed-off-by: jiafu zhang <jiafuzha@apache.org>
Signed-off-by: Xue, Chendi <chendi.xue@intel.com>
Co-authored-by: Carson Wang <carson.wang@intel.com>
Signed-off-by: Chendi.Xue <chendi.xue@intel.com>
Signed-off-by: Xue, Chendi <chendi.xue@intel.com>
Signed-off-by: Xue, Chendi <chendi.xue@intel.com>
Copy link
Contributor

@carsonwang carsonwang left a comment

Choose a reason for hiding this comment

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

CI passed. Thanks @xuechendi !

@carsonwang carsonwang merged commit 6d33b49 into intel:main Mar 26, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants