NextChat
NextChat copied to clipboard
[Feature Request] x.ai新api功能,Live search支持
🥰 需求描述
https://docs.x.ai/docs/guides/live-search x.ai的api增加了live search的支持,通过参数可以选择
🧐 解决方案
import os import requests
url = "https://api.x.ai/v1/chat/completions" headers = { "Content-Type": "application/json", "Authorization": f"Bearer {os.getenv('XAI_API_KEY')}" } payload = { "messages": [ { "role": "user", "content": "Provide me a digest of world news in the last 24 hours." } ], "search_parameters": { "mode": "auto" }, "model": "grok-3-latest" }
response = requests.post(url, headers=headers, json=payload) print(response.json())
简单的例子,json形式的一个新参数和三个选项可以提供开关,文档如上 还有一个返回的参数,应该只需要增加这两个就可以
📝 补充信息
No response
Bot detected the issue body's language is not English, translate it automatically.
Title: [Feature Request] x.ai new api function, Live search supports
🥰 Requirement description
https://docs.x.ai/docs/guides/live-search x.ai's API adds live search support, and you can select it through parameters
🧐 Solution
import os import requests
url = "https://api.x.ai/v1/chat/completes" headers = { "Content-Type": "application/json", "Authorization": f"Bearer {os.getenv('XAI_API_KEY')}" } payload = { "messages": [ { "role": "user", "content": "Provide me a digest of world news in the last 24 hours." } ], "search_parameters": { "mode": "auto" }, "model": "grok-3-latest" }
response = requests.post(url, headers=headers, json=payload) print(response.json())
A simple example, a new parameter and three options in the form of json can provide switches, the documentation is as above There is also a return parameter, you should only need to add these two to
📝 Supplementary information
No response