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

feat: add apichain #559

Merged
merged 1 commit into from
Jan 17, 2024
Merged

feat: add apichain #559

merged 1 commit into from
Jan 17, 2024

Conversation

Abirdcfly
Copy link
Collaborator

@Abirdcfly Abirdcfly commented Jan 15, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it

add apichain, which allows LLM to use the provided api documentation to intelligently infer which requests need to be sent to which api in order to get the information it needs, and to analyze the resulting resp to answer the user's question.

for example:

we add a apidoc for movie info:

提供如下API接口:
https://api.wmdb.tv/api/v1/movie/search?q=英雄本色&limit=10&lang=Cn
其中,q为搜索项,必填。如果是中文,请使用urlencode对这个字段进行编码,英文则不需要
limit为搜索条数,可选,默认填10
lang为搜索语言,可选,默认填Cn

and we ask Furious 7 的主演有谁?, then zhipuai will check this api and build a request https://api.wmdb.tv/api/v1/movie/search?q=Furious+7&limit=10&lang=Cn, in apichain, go http will send this request, then zhipuai use the response to make result for us.

We used LLM 2 times in this process, the first time we used prompt as:

You are given the API Documentation:

{{.api_docs}}

Your task is to construct a full API JSON object based on the provided input. The input could be a question that requires an API call for its answer, or a direct or indirect instruction to consume an API. The input will be unpredictable and could come from a user or an agent.

Your goal is to create an API call that accurately reflects the intent of the input. Be sure to exclude any unnecessary data in the API call to ensure efficiency.

Input: {{.input}}

Respond with a JSON object.

{
    "method":  [the HTTP method for the API call, such as GET or POST],
    "headers": [object representing the HTTP headers required for the API call, always add a "Content-Type" header],
    "url": 	   [full for the API call],
    "body":    [object containing the data sent with the request, if needed]
}

The second use of prompt is the above prompt and add the following:

Here is the response from the API:

{{.api_response}}

Now, summarize this response. Your summary should reflect the original input and highlight the key information from the API response that answers or relates to that input. Try to make your summary concise, yet informative.

Summary:

we will see:

# curl -XPOST http://127.0.0.1:8081/chat --data '{"query":"Furious 7 的主演有谁?","response_mode":"blocking","conversion_id":"","app_name":"movie-bot", "app_namespace":"arcadia"}'

{"conversation_id":"8e038628-6ae7-435d-8a6e-b5b5cb9588b4","message_id":"c9730177-0ad2-4c59-a279-66593f60676a","message":"您询问了《Furious 7》的主演,根据API的 返回结果,我们可以看到以下信息:\n\n1. 《Furious 7》的别名有:狂野时速7(港)、玩命关头7(台)、Fast \u0026 Furious 7。\n2. 该电影的类型是动作/犯罪,导演是詹姆斯·万。\n3. 主演包括范·迪塞尔、米歇尔·罗德里格兹、杰森·斯坦森、查理兹·塞隆等。\n4. 电影的上映日期是2015年4月3日,时长为8220秒(约1小时22分钟)。\n5. 该电影在豆瓣上的评分为8.3分,有404841人投票。\n\n综上所述,《Furious 7》的主演包括范·迪塞尔、米歇尔·罗德里格兹、杰森·斯坦森、查理兹·塞隆等,是一部动作/犯罪的影片,于2015年4月3 日上映。","created_at":"2024-01-17T01:46:25.028139325Z"}

Advantages:

Intelligent to determine which api should be used, which request parameters should be sent, what exactly are the parameters that should be sent.

Disadvantages:

All intelligence depends on the LLM if the LLM is poorer, the result obtained after waiting for 2 LLMs + one request to the api may not be ideal.
zhipu's LLMs have a high probability of failing to process all the examples above, even for the highest level of the pro model, conversely, chatgpt-3.5 always succeeds.

Which issue(s) this PR fixes

Fixes #

Special notes for your reviewer

@Abirdcfly Abirdcfly force-pushed the apichain branch 7 times, most recently from f5933ad to df75805 Compare January 15, 2024 09:53
@Abirdcfly Abirdcfly changed the title feat: knowledgebase support more granular update feat: add apichain Jan 15, 2024
@Abirdcfly Abirdcfly marked this pull request as ready for review January 15, 2024 09:56
@github-actions github-actions bot requested review from 0xff-dev and bjwswang January 15, 2024 09:56
@Abirdcfly Abirdcfly force-pushed the apichain branch 3 times, most recently from dd946cf to b155029 Compare January 16, 2024 09:39
@Abirdcfly Abirdcfly marked this pull request as draft January 16, 2024 09:53
Signed-off-by: Abirdcfly <fp544037857@gmail.com>
@Abirdcfly Abirdcfly marked this pull request as ready for review January 17, 2024 01:49
@Abirdcfly
Copy link
Collaborator Author

@nkwangleiGIT @bjwswang @liutianyi0801 pls see the comment #559 (comment)

@nkwangleiGIT
Copy link
Contributor

for the possibility to fail due to LLM not intelligent enough, I think we should have a better explanation to the end user, let's do it in future release.

@nkwangleiGIT nkwangleiGIT merged commit 27b2085 into kubeagi:main Jan 17, 2024
10 checks passed
@Abirdcfly Abirdcfly deleted the apichain branch January 17, 2024 06:31
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