已比較的版本

索引鍵

  • 此行已新增。
  • 此行已移除。
  • 格式已變更。

您可以透過以下實作來實現 Multiple Functions 的場景。如以下的例子是撈取對話歷史加上

system prompt後,餵入兩個 functions (summarization & extract_keywords) 讓模型依據對話歷史回傳對應 function 的 arguments。透過以下的 plugin 可以協助 summary 一段文章或者取出文章當中的重點

  1. summarication: 透過此 function 可以提供文章的摘要

  2. focal_points: 透過此 function 可以列文章的重點

程式碼區塊
languagepy
import json
from pyodide.http import pyfetch

async def main():
    response = await chat(
        conversation=CURRENT_CONVERSATION + [
            {
            "role": "system",
            "content": "Only use the functions you have been provided with."
            }
        ],
        functions=[
            {
                "name": "summarization",
                "description": "summarize the conversation",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "summary": {
                            "type": "string",
                            "description": "the summary of the conversation"
                        }
                    },
                    "required": ["summary"]
                }
            },
            {
                "name": "extractfocal_keywordspoints",
                "description": "extracting fromextract the focal points of the conversation",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "keywordspoints": {
                            "type": "array",
                            "items": {
                                "type": "string",
                                "description": "oneextract the keywordfocal extractedpoints fromof the conversation"
                            }
                        }
                    },
                    "required": ["keywordspoints"]
                }
            }
        ]
    )
    if 'function_call' in response:
        if response['function_call']['name'] == 'summarization':
            print("The summary of the converstaion is ", json.loads(response['function_call']['arguments'])['summary'])
        elif response['function_call']['name'] == 'extractedfocal_keywordspoints':
            print("The keywordsfocal points of the converstaion are ", json.loads(response['function_call']['arguments'])['keywordspoints'])
    else:
        print(response['content'])

await main()