MCPcopy Index your code
hub / github.com/ModelTC/LightLLM / function_call

Method function_call

test/test_api/test_openai_api.py:117–134  ·  view source on GitHub ↗

Function calling

(self, message: str, tools: List[Dict], tool_choice: str = "auto", **kwargs)

Source from the content-addressed store, hash-verified

115 raise Exception(f"API调用失败: {response.status_code} - {response.text}")
116
117 def function_call(self, message: str, tools: List[Dict], tool_choice: str = "auto", **kwargs) -> Dict[str, Any]:
118 """Function calling"""
119 data = {
120 "model": self.model_name,
121 "messages": [{"role": "user", "content": message}],
122 "tools": tools,
123 "tool_choice": tool_choice,
124 "temperature": kwargs.get("temperature", 0.7),
125 "max_tokens": kwargs.get("max_tokens", 1000),
126 **kwargs,
127 }
128
129 response = requests.post(f"{self.base_url}/v1/chat/completions", headers=self.headers, json=data)
130
131 if response.status_code == 200:
132 return response.json()
133 else:
134 raise Exception(f"API调用失败: {response.status_code} - {response.text}")
135
136 def stream_function_call(self, message: str, tools: List[Dict], tool_choice: str = "auto", **kwargs):
137 """stream Function calling"""

Callers 1

test_function_callFunction · 0.95

Calls 1

getMethod · 0.45

Tested by

no test coverage detected