From cd766c6289f8c95c7318b0d9508b3ba65bb0fd79 Mon Sep 17 00:00:00 2001 From: neil Date: Wed, 23 Jul 2025 14:09:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20codeblock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/products/apis/texts/json-output.md | 2 +- docs/products/apis/texts/lang-style.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/products/apis/texts/json-output.md b/docs/products/apis/texts/json-output.md index d2d2baa..2771f1f 100644 --- a/docs/products/apis/texts/json-output.md +++ b/docs/products/apis/texts/json-output.md @@ -46,7 +46,7 @@ JSON 是世界上应用最广泛的数据交换格式之一。而符合 [JSON Sc 再添加一些 prompt 提升可靠性,AI 将会根据输入提取数据生成标准的 JSON: -```python +```python showLineNumbers title="python" from langchain_openai import ChatOpenAI model_name = "Qwen2.5-72B-Instruct" base_url = "{{SITE_URL}}/v1" diff --git a/docs/products/apis/texts/lang-style.md b/docs/products/apis/texts/lang-style.md index c3004c9..7aa84a4 100644 --- a/docs/products/apis/texts/lang-style.md +++ b/docs/products/apis/texts/lang-style.md @@ -14,7 +14,7 @@ sidebar_position: 4 首先创建 openai client。您也可以通过 curl 或者 javascript 等方式调用,详情参考文档 [通过 curl 快速使用大模型能力](text#示例一通过-curl-快速使用大模型能力)。 -```python +```python showLineNumbers title="python" from openai import OpenAI import json base_url = "{{SITE_URL}}/v1" @@ -27,7 +27,7 @@ client = OpenAI(base_url=base_url, api_key="访问令牌") 在 `messages` 中添加一个 `role` 为 `system` 的消息,内容为您的提示词。例如,以下代码将创建一个名为“萌萌”的二次元女生角色,并使用颜文字和可爱语气与用户交流。 -```python +```python showLineNumbers title="python" completion = client.chat.completions.create( model=model_name, stream=True, @@ -45,7 +45,7 @@ completion = client.chat.completions.create( 解析事件流中的 JSON 数据可以实时打印出 AI 回答的消息。 -```python +```python showLineNumbers title="python" for chunk in completion: print(chunk.choices[0].delta.content, end="") ``` -- Gitee From 3302e3955d9c865942341b3dddd020dc4138661b Mon Sep 17 00:00:00 2001 From: neil Date: Wed, 23 Jul 2025 16:20:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E4=BB=A3=E7=A0=81=E5=9D=97?= =?UTF-8?q?=EF=BC=8C=20=E5=A2=9E=E5=8A=A0=E8=A1=8C=E5=8F=B7=EF=BC=8C?= =?UTF-8?q?=E8=AF=AD=E8=A8=80=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/getting-started.md | 46 +++---- docs/products/apis/3d/index.md | 2 +- docs/products/apis/documents/ocr.md | 2 +- docs/products/apis/embeddings/index.md | 6 +- docs/products/apis/images-vision/faceid.md | 8 +- docs/products/apis/images-vision/fuzzy.md | 2 +- .../apis/images-vision/object-detection.md | 12 +- .../products/apis/images-vision/text2image.md | 4 +- docs/products/apis/images-vision/visions.md | 2 +- docs/products/apis/moderations/index.md | 4 +- .../apis/speeches/speech-recognition.md | 2 +- docs/products/apis/speeches/text-to-speech.md | 2 +- docs/products/apis/texts/function-calling.md | 8 +- docs/products/apis/texts/json-output.md | 6 +- docs/products/apis/texts/text-comlpetion.md | 56 ++++---- docs/products/apis/texts/text-generation.md | 128 +++++++++--------- docs/products/apis/videos/index.md | 2 +- docs/products/models/download.md | 8 +- 18 files changed, 151 insertions(+), 149 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index 85bc526..01ce013 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -39,29 +39,29 @@ hide_table_of_contents: true 3. 关于 API 的更多细节,您可以参考 [API 文档](./openapi/v1)。 4. 一个最简单的 Python 调用大模型的示例代码: - ```python - import requests - - url = "{{SITE_URL}}/v1/chat/completions" - headers = { - "Authorization": "Bearer ", - "Content-Type": "application/json" - } - data = { - "model": "DeepSeek-R1", # 模型名称 - "messages": [ - {"role": "user", "content": "请帮我写一首关于春天的五言绝句"} - ], - "max_tokens": 100, # 最大生成 token 数 - "temperature": 0.7 # 控制生成文本的随机性 - } - response = requests.post(url, headers=headers, json=data) - if response.status_code == 200: - result = response.json() - print("模型回应:", result['choices'][0]['message']['content']) - else: - print("请求失败,状态码:", response.status_code, "错误信息:", response.text) - ``` +```python showLineNumbers title="python" +import requests + +url = "{{SITE_URL}}/v1/chat/completions" +headers = { + "Authorization": "Bearer ", + "Content-Type": "application/json" +} +data = { + "model": "DeepSeek-R1", # 模型名称 + "messages": [ + {"role": "user", "content": "请帮我写一首关于春天的五言绝句"} + ], + "max_tokens": 100, # 最大生成 token 数 + "temperature": 0.7 # 控制生成文本的随机性 +} +response = requests.post(url, headers=headers, json=data) +if response.status_code == 200: + result = response.json() + print("模型回应:", result['choices'][0]['message']['content']) +else: + print("请求失败,状态码:", response.status_code, "错误信息:", response.text) +``` ## 接下来 diff --git a/docs/products/apis/3d/index.md b/docs/products/apis/3d/index.md index 02313bf..95861be 100644 --- a/docs/products/apis/3d/index.md +++ b/docs/products/apis/3d/index.md @@ -35,7 +35,7 @@ 以下是使用 Python 调用 3D 生成模型的示例代码: -```python +```python showLineNumbers title="python" import requests from requests_toolbelt import MultipartEncoder import os diff --git a/docs/products/apis/documents/ocr.md b/docs/products/apis/documents/ocr.md index 1a82e8c..dbd32a4 100644 --- a/docs/products/apis/documents/ocr.md +++ b/docs/products/apis/documents/ocr.md @@ -34,7 +34,7 @@ curl {{SITE_URL}}/v1/images/ocr \ -```python +```python showLineNumbers title="python" import requests API_URL = "{{SITE_URL}}/v1/images/ocr" HEADERS = { diff --git a/docs/products/apis/embeddings/index.md b/docs/products/apis/embeddings/index.md index 1836c6f..577b270 100644 --- a/docs/products/apis/embeddings/index.md +++ b/docs/products/apis/embeddings/index.md @@ -24,7 +24,7 @@ import ServerlessAPIServices from '@site/src/components/ServerlessAPIServices'; 示例代码: -```python +```python showLineNumbers title="python" from openai import OpenAI client = OpenAI( @@ -51,7 +51,7 @@ response = client.embeddings.create( 示例代码: -```python +```python showLineNumbers title="python" from openai import OpenAI client = OpenAI( @@ -75,7 +75,7 @@ response = client.embeddings.create( 示例代码: -```python +```python showLineNumbers title="python" import requests API_URL = "{{SITE_URL}}/v1/rerank" diff --git a/docs/products/apis/images-vision/faceid.md b/docs/products/apis/images-vision/faceid.md index 8b2c767..6f1303c 100644 --- a/docs/products/apis/images-vision/faceid.md +++ b/docs/products/apis/images-vision/faceid.md @@ -20,7 +20,7 @@ sidebar_position: 6 首先获取您的 [访问令牌]({{SITE_URL}}/dashboard/settings/tokens),然后可定义请求函数如下: -```python +```python showLineNumbers title="python" import requests import base64 from PIL import Image @@ -44,7 +44,7 @@ def query(payload): 请求方式如下,不过需要注意 `flux` 模型的提示词 (prompt) 需要是 **英文**。 -```python +```python showLineNumbers title="python" output = query({ "model": "flux-1-schnell", "image": "liuyifei.png", @@ -90,7 +90,7 @@ output = query({ 数据结果为 Base64 编码的图像,因此需要解码后才能保存,解包、解码如下: -```python +```python showLineNumbers title="python" b64data = output['data'][0]['b64_json'] img = Image.open(BytesIO(base64.b64decode(b64data))) img.save("/path/to/save/res.jpg") @@ -103,7 +103,7 @@ img.show() 完整示例代码如下: -```python +```python showLineNumbers title="python" import requests import base64 from PIL import Image diff --git a/docs/products/apis/images-vision/fuzzy.md b/docs/products/apis/images-vision/fuzzy.md index 2949132..2551392 100644 --- a/docs/products/apis/images-vision/fuzzy.md +++ b/docs/products/apis/images-vision/fuzzy.md @@ -69,7 +69,7 @@ Serverless API 提供了接口快速体验的界面,可以快速体验接口 完成了功能体验和验证后,接下来我们可以通过代码调用,将上述功能集成到自己的应用中。 -```python +```python showLineNumbers title="python" import requests API_URL = "{{SITE_URL}}/serverless-api?model=Kolors&operation=205&maximized=1" diff --git a/docs/products/apis/images-vision/object-detection.md b/docs/products/apis/images-vision/object-detection.md index 057bffd..4d9a807 100644 --- a/docs/products/apis/images-vision/object-detection.md +++ b/docs/products/apis/images-vision/object-detection.md @@ -20,7 +20,7 @@ sidebar_position: 7 接口的使用以 Python 代码为例,下面将分别演示“图像描述”与“目标识别”两个功能项的使用方法。在开始前先定义请求函数如下: -```python +```python showLineNumbers title="python" import requests headers = { @@ -50,7 +50,7 @@ def query(url, payload): 该功能可以获取用户输入的图片的自然语言描述。 使用上文的 query 函数,发起请求如下: -```python +```python showLineNumbers title="python" output = query(url_caption, { "model": "Florence-2-large", "image": "path/to/image.jpg", @@ -97,7 +97,7 @@ output = query(url_caption, { 使用如下的请求代码: -```python +```python showLineNumbers title="python" output = query({ "model": "Florence-2-large", "image": "path/to/image.jpg", @@ -223,7 +223,7 @@ output = query({ 注意,若使用了 `prompt` 参数,`caption_level` 参数将会失效,标签内容的详细程度将由提示词决定。 -```python +```python showLineNumbers title="python" output = query(url_onject_detection, { "model": "Florence-2-large", "image": "path/to/image.jpg", @@ -271,7 +271,7 @@ output = query(url_onject_detection, { 在目标识别获得标签后,为了更好的看到标记效果,我们提供一个绘制结果的函数供参考,代码如下: -```python +```python showLineNumbers title="python" from PIL import Image, ImageDraw, ImageFont def draw_labelled_bbox(image, bbox, label): @@ -342,7 +342,7 @@ image.save("/path/to/save.jpg") 将结果转为python中的 `dict` 类,我们使用如下代码调用函数: -```python +```python showLineNumbers title="python" image = loaded_image label = obj['label'] bbox = obj['bbox'] diff --git a/docs/products/apis/images-vision/text2image.md b/docs/products/apis/images-vision/text2image.md index 3342d2e..528f25a 100644 --- a/docs/products/apis/images-vision/text2image.md +++ b/docs/products/apis/images-vision/text2image.md @@ -28,7 +28,7 @@ import ServerlessAPIServices from '@site/src/components/ServerlessAPIServices'; 您可以使用 OpenAI 的 SDK 来调用文生图模型。以下是一个使用 Python 的示例: -```python +```python showLineNumbers title="python" from openai import OpenAI import base64 @@ -60,7 +60,7 @@ with open("Kolors-output.png", "wb") as f: 如果您不想使用 OpenAI 的 SDK,也可以直接使用 `requests` 库来调用文生图模型。以下是一个使用 Python 的示例: -```python +```python showLineNumbers title="python" import requests import base64 import json diff --git a/docs/products/apis/images-vision/visions.md b/docs/products/apis/images-vision/visions.md index 0408a00..d8c0505 100644 --- a/docs/products/apis/images-vision/visions.md +++ b/docs/products/apis/images-vision/visions.md @@ -24,7 +24,7 @@ import ServerlessAPIServices from '@site/src/components/ServerlessAPIServices'; ## 示例代码 -```python +```python showLineNumbers title="python" from openai import OpenAI client = OpenAI( diff --git a/docs/products/apis/moderations/index.md b/docs/products/apis/moderations/index.md index f01eb2a..9a48dba 100644 --- a/docs/products/apis/moderations/index.md +++ b/docs/products/apis/moderations/index.md @@ -22,7 +22,7 @@ Security-semantic-filtering 是一种用于增强系统安全性的技术,通 ### 文本内容风控检查 -```python +```python showLineNumbers title="python" from openai import OpenAI client = OpenAI( @@ -43,7 +43,7 @@ response = client.moderations.create( ### 图片检查 -```python +```python showLineNumbers title="python" from openai import OpenAI client = OpenAI( diff --git a/docs/products/apis/speeches/speech-recognition.md b/docs/products/apis/speeches/speech-recognition.md index df75223..1af4e2a 100644 --- a/docs/products/apis/speeches/speech-recognition.md +++ b/docs/products/apis/speeches/speech-recognition.md @@ -28,7 +28,7 @@ import ServerlessAPIServices from '@site/src/components/ServerlessAPIServices'; 以下是使用 Python 调用语音识别模型的示例代码: -```python +```python showLineNumbers title="python" import requests from requests_toolbelt import MultipartEncoder import os diff --git a/docs/products/apis/speeches/text-to-speech.md b/docs/products/apis/speeches/text-to-speech.md index bdebb85..314551e 100644 --- a/docs/products/apis/speeches/text-to-speech.md +++ b/docs/products/apis/speeches/text-to-speech.md @@ -34,7 +34,7 @@ import ServerlessAPIServices from '@site/src/components/ServerlessAPIServices'; 以下是使用 Python 调用语音生成模型的示例代码: -```python +```python showLineNumbers title="python" from openai import OpenAI client = OpenAI( diff --git a/docs/products/apis/texts/function-calling.md b/docs/products/apis/texts/function-calling.md index 0870b84..0df9b5f 100644 --- a/docs/products/apis/texts/function-calling.md +++ b/docs/products/apis/texts/function-calling.md @@ -25,7 +25,7 @@ sidebar_position: 2 首先组合tools参数,下面向大模型描述了一个名为 `get_current_weather` 的函数,函数传入参数为 `city`, `x` , `y` ,函数能力是通过城市名和经纬度获取地点的天气情况: -```python +```python showLineNumbers title="python" tools = [ { "type": "function", @@ -60,7 +60,7 @@ tools = [ 将上文拼凑好的 `tools` 参数传入客户端中,解析响应的请求,并根据请求调用定义好的 `get_current_weather` 函数。 -```python +```python showLineNumbers title="python" import json completion_tool = client.chat.completions.create( @@ -125,7 +125,7 @@ eval(f'{function_res.name}(**{arguments_res})') Langchain 等库提供了更多简便的工具和写法,首先安装必要的库: -``` +```bash title="bash" pip install \ langchain==0.3.3 \ langgraph==0.2.38 \ @@ -144,7 +144,7 @@ pip install \ 下面实现让 AI 获取新闻,编写并执行 Python 代码,将新闻写入到 ./news.txt 文件中”: -```python +```python showLineNumbers title="python" from langchain_openai import ChatOpenAI from langchain.tools import tool from langchain_community.document_loaders import WebBaseLoader diff --git a/docs/products/apis/texts/json-output.md b/docs/products/apis/texts/json-output.md index 2771f1f..03989ca 100644 --- a/docs/products/apis/texts/json-output.md +++ b/docs/products/apis/texts/json-output.md @@ -23,7 +23,7 @@ JSON 是世界上应用最广泛的数据交换格式之一。而符合 [JSON Sc ## 示例代码 -```json +```python showLineNumbers title="python" "guided_json": """{ "type": "object", "properties": { @@ -48,11 +48,13 @@ JSON 是世界上应用最广泛的数据交换格式之一。而符合 [JSON Sc ```python showLineNumbers title="python" from langchain_openai import ChatOpenAI + model_name = "Qwen2.5-72B-Instruct" base_url = "{{SITE_URL}}/v1" # {{SITE_URL}}/dashboard/settings/tokens 获取您的访问令牌 GITEE_AI_API_KEY = "" -llm = ChatOpenAI(model=model_name, api_key=GITEE_AI_API_KEY, base_url=base_url, streaming=True, temperature=0.1, presence_penalty=1.05, top_p=0.9, +llm = ChatOpenAI(model=model_name, api_key=GITEE_AI_API_KEY, base_url=base_url, streaming=True, temperature=0.1, + presence_penalty=1.05, top_p=0.9, extra_body={ "guided_json": """{ "type": "object", diff --git a/docs/products/apis/texts/text-comlpetion.md b/docs/products/apis/texts/text-comlpetion.md index 35b8bbe..918c4cd 100644 --- a/docs/products/apis/texts/text-comlpetion.md +++ b/docs/products/apis/texts/text-comlpetion.md @@ -72,32 +72,33 @@ AI 模型响应: 1. **获取访问凭证**:登录模力方舟控制台,在 [**工作台 -> 访问令牌**]({{SITE_URL}}/dashboard/settings/tokens) 中创建访问令牌。 2. **安装客户端**:以 OpenAI 客户端为例,首先安装依赖: - ```bash - pip install openai -i https://mirrors.cloud.tencent.com/pypi/simple - ``` - 如果您有 javascript 经验可使用 [OpenAI nodejs 客户端](https://www.npmjs.com/package/openai/) - - 通过简单接口调用,生成指定内容: - ```python - from openai import OpenAI - - client = OpenAI( - base_url="{{SITE_URL}}/v1", - api_key="您的访问令牌" - ) - - response = client.completions.create( - model="Qwen2.5-72B-Instruct", - prompt="春天来了,公园里的花儿", - max_tokens=50, - temperature=0.8 - ) - - print(response.choices[0].text) - ``` +```bash +pip install openai -i https://mirrors.cloud.tencent.com/pypi/simple +``` + +如果您有 javascript 经验可使用 [OpenAI nodejs 客户端](https://www.npmjs.com/package/openai/) + +通过简单接口调用,生成指定内容: +```python showLineNumbers title="python" +from openai import OpenAI + +client = OpenAI( + base_url="{{SITE_URL}}/v1", + api_key="您的访问令牌" +) + +response = client.completions.create( + model="Qwen2.5-72B-Instruct", + prompt="春天来了,公园里的花儿", + max_tokens=50, + temperature=0.8 +) +print(response.choices[0].text) +``` + ### 流式响应 对于较长文本的补全,启用流式响应 `stream=True` 可实时获取补全内容,提升用户体验: -```python +```python showLineNumbers title="python" from openai import OpenAI client = OpenAI( @@ -154,8 +155,7 @@ for chunk in stream: 若希望补全内容与输入文本风格一致(如正式 / 非正式、专业 / 通俗、特定文体),可在 prompt 中体现或通过 `instructions` 参数指定。 **示例:通过 instructions 设定风格** -```python - +```python showLineNumbers title="python" client.completions.create( model="Qwen2.5-72B-Instruct", prompt="余尝闻,世间至美之物,莫过于", @@ -169,7 +169,7 @@ client.completions.create( ### 利用上下文提示 对于长文本片段的补全,确保提供足够的上下文信息,帮助模型理解文本的主题、逻辑和风格。 **示例:** -```python +```python showLineNumbers title="python" prompt = """ 以下是一篇关于环境保护的文章片段,请继续补全: @@ -185,7 +185,7 @@ client.completions.create( ### 少样本补全示例 通过在 `prompt` 中提供 “输入片段 + 补全示例”,可以引导模型快速掌握特定补全模式。 **示例:邮件回复片段补全** -```python +```python showLineNumbers title="python" prompt = """ 请按照以下示例的风格,补全邮件回复片段: diff --git a/docs/products/apis/texts/text-generation.md b/docs/products/apis/texts/text-generation.md index 3ca6f3e..a83757d 100644 --- a/docs/products/apis/texts/text-generation.md +++ b/docs/products/apis/texts/text-generation.md @@ -132,40 +132,40 @@ AI 模型响应: 1. **获取访问凭证**:登录模力方舟控制台,在 [**工作台 -> 访问令牌**]({{SITE_URL}}/dashboard/settings/tokens) 中创建访问令牌。 2. **安装客户端**:以 OpenAI 客户端为例,首先安装依赖: - ```bash - pip install openai -i https://mirrors.cloud.tencent.com/pypi/simple - ``` - 如果您有 javascript 经验可使用 [OpenAI nodejs 客户端](https://www.npmjs.com/package/openai/) +```bash +pip install openai -i https://mirrors.cloud.tencent.com/pypi/simple +``` +如果您有 javascript 经验可使用 [OpenAI nodejs 客户端](https://www.npmjs.com/package/openai/) - 通过简单接口调用,生成指定内容: +通过简单接口调用,生成指定内容: - ```python - from openai import OpenAI - import json +```python showLineNumbers title="python" +from openai import OpenAI +import json - base_url = "{{SITE_URL}}/v1" +base_url = "{{SITE_URL}}/v1" - model_name = "Qwen2.5-72B-Instruct" +model_name = "Qwen2.5-72B-Instruct" - # {{SITE_URL}}/dashboard/settings/tokens 获取您的访问令牌 - client = OpenAI(base_url=base_url, api_key="GITEE_AI_API_KEY") +# {{SITE_URL}}/dashboard/settings/tokens 获取您的访问令牌 +client = OpenAI(base_url=base_url, api_key="GITEE_AI_API_KEY") - completion = client.chat.completions.create( - model=model_name, # 指定模型名称 例如 Qwen2.5-72B-Instruct,可访问 {{SITE_URL}}/serverless-api 查看 - stream=True, - temperature=0.7, - top_p=0.95, - frequency_penalty=1.05, - messages=[ - {"role": "system", "content": "你是一个有用的助手。"}, - {"role": "user", "content": "写一个 python 简明教程"} - ] - ) +completion = client.chat.completions.create( + model=model_name, # 指定模型名称 例如 Qwen2.5-72B-Instruct,可访问 {{SITE_URL}}/serverless-api 查看 + stream=True, + temperature=0.7, + top_p=0.95, + frequency_penalty=1.05, + messages=[ + {"role": "system", "content": "你是一个有用的助手。"}, + {"role": "user", "content": "写一个 python 简明教程"} + ] +) - for chunk in completion: - print(chunk.choices[0].delta.content, end="") +for chunk in completion: + print(chunk.choices[0].delta.content, end="") - ``` +``` 除了纯文本,您还可以让模型以 JSON 格式返回结构化数据 —— 此功能称为 [**结构化输出**](json-output.md) ,在模力方舟中可通过 `guided_json` 参数实现。 @@ -173,28 +173,28 @@ AI 模型响应: 对于长文本生成,启用流式响应 `stream=True` 可实时获取结果,减少等待时间: -```python - stream = client.chat.completions.create( - model="Qwen2.5-72B-Instruct",# 替换成指定模型名称 - messages=[ - {"role": "user", "content": "写一段关于人工智能发展历程的短文"} - ], - stream=True, # 启用流式输出 - temperature=0.6 - ) - - for chunk in stream: - if chunk.choices[0].delta.content: - print(chunk.choices[0].delta.content, end="") +```python showLineNumbers title="python" +stream = client.chat.completions.create( + model="Qwen2.5-72B-Instruct",# 替换成指定模型名称 + messages=[ + {"role": "user", "content": "写一段关于人工智能发展历程的短文"} + ], + stream=True, # 启用流式输出 + temperature=0.6 +) + +for chunk in stream: + if chunk.choices[0].delta.content: + print(chunk.choices[0].delta.content, end="") ``` ### 核心参数说明 - **tool_choice**: 支持 `auto` 由模型自动选择工具,也支持强制选择工具,写法如下: - ```json - "tool_choice": {"type": "function", "function": {"name": "function_name"}}, - ``` +```json +"tool_choice": {"type": "function", "function": {"name": "function_name"}}, +``` - **guided_json**:让模型以指定的 JSON Schema 响应。不建议与 `tools`、`guided_json` 同时传入。 @@ -202,13 +202,13 @@ AI 模型响应: - **guided_choice**: 让模型选择提供的字符串列表之一,不建议与 `tools`、`guided_json` 同时传入。 - 例如判断用户输入正负面性可传入: +例如判断用户输入正负面性可传入: - ```json - "guided_choice": ["正面", "负面", "中性"] - ``` +```json +"guided_choice": ["正面", "负面", "中性"] +``` - 其他参数详见 [接口文档]({{SITE_URL}}/docs/openapi/v1#tag/文本生成) +其他参数详见 [接口文档]({{SITE_URL}}/docs/openapi/v1#tag/文本生成) ## 模型选择 @@ -245,25 +245,25 @@ AI 模型响应: 1. **instructions 参数**:全局指令优先级 - `instructions` 为模型提供**高级指令**(语气、目标、示例等),优先级高于 `input` 内容。 +`instructions` 为模型提供**高级指令**(语气、目标、示例等),优先级高于 `input` 内容。 - ```javascript - import OpenAI from 'openai'; - const client = new OpenAI({ - baseURL: '{{SITE_URL}}/v1', - apiKey: '您的模力方舟API密钥', - }); +```javascript +import OpenAI from 'openai'; +const client = new OpenAI({ + baseURL: '{{SITE_URL}}/v1', + apiKey: '您的模力方舟API密钥', +}); - const response = await client.responses.create({ - model: '对应模型名称', - // 定义全局风格/规则 - instructions: '用老奶奶的语气说话,带点生活化的比喻和慈祥的唠叨', - input: 'JavaScript中的分号是可选的吗?', - }); +const response = await client.responses.create({ + model: '对应模型名称', + // 定义全局风格/规则 + instructions: '用老奶奶的语气说话,带点生活化的比喻和慈祥的唠叨', + input: 'JavaScript中的分号是可选的吗?', +}); - console.log(response.output_text); - // 示例输出:"哎哟孩子啊,JavaScript里这个分号嘛,就像咱们包饺子放盐——可放可不放!不过奶奶跟你说啊,该放的时候还是得放,不然煮出来容易破皮(出bug)哩!" - ``` +console.log(response.output_text); +// 示例输出:"哎哟孩子啊,JavaScript里这个分号嘛,就像咱们包饺子放盐——可放可不放!不过奶奶跟你说啊,该放的时候还是得放,不然煮出来容易破皮(出bug)哩!" +``` 2. **消息角色**:精细化场景控制 @@ -360,7 +360,7 @@ var first_name = "安娜"; 2. 提示词缓存优化 将重复使用的固定内容(如系统指令)放在提示词开头,利用缓存减少计算成本: -```python +```python showLineNumbers title="python" # 高效结构:固定内容在前,动态内容在后 messages = [ {"role": "system", "content": "固定的系统指令,如'你是电商客服,需礼貌回答订单问题'"}, # 可被缓存 diff --git a/docs/products/apis/videos/index.md b/docs/products/apis/videos/index.md index f9770bc..d0c0c6e 100644 --- a/docs/products/apis/videos/index.md +++ b/docs/products/apis/videos/index.md @@ -22,7 +22,7 @@ import ServerlessAPIServices from '@site/src/components/ServerlessAPIServices'; 模力方舟上所有的视频模型皆使用异步接口方式调用,详情请看模型体验页面的示例代码,或者参考 [异步接口使用指南]({{SITE_URL}}/docs/openapi/v1#tag/异步任务)。 -```python +```python showLineNumbers title="python" import requests import time import json diff --git a/docs/products/models/download.md b/docs/products/models/download.md index ea7a110..71d9f01 100644 --- a/docs/products/models/download.md +++ b/docs/products/models/download.md @@ -25,7 +25,7 @@ export HF_HOME=~/.cache/gitee-ai - 或者,在要执行的 python 代码 **头部** 粘贴以下代码: -```python +```python showLineNumbers title="python" import os os.environ["HF_HOME"] = "~/.cache/gitee-ai" os.environ["HF_ENDPOINT"] = "https://hf-api.gitee.com" @@ -41,21 +41,21 @@ export HF_TOKEN= [huggingface_hub](https://github.com/huggingface/huggingface_hub): -```python +```python showLineNumbers title="python" from huggingface_hub import hf_hub_download hf_hub_download("hf-models/sdxl-turbo", "sd_xl_turbo_1.0.safetensors", local_dir="./models") ``` [transformers](https://github.com/huggingface/transformers): -```python +```python showLineNumbers title="python" from transformers import pipeline pipe = pipeline("text-generation", model="gpt2") ``` [diffusers](https://github.com/huggingface/diffusers): -```python +```python showLineNumbers title="python" from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0") ``` -- Gitee