# 视觉

&#x20;简介 Afarensis GPT-4 with Vision（简称 GPT-4V）为开发人员提供了一种革命性的能力，使得模型能够接收图像并回答有关它们的问题，突破了传统语言模型系统仅限于处理文本输入的局限。

主要特征 视觉增强的 GPT-4：具备视觉能力的 GPT-4 提供了对图像内容的理解能力，同时保持了在文本任务上的高性能。 多样化应用：视觉能力为 GPT-4 模型带来了更广泛的应用范围。 API 支持：目前通过模型和 Chat Completions API 支持图像输入，但 Assistants API 尚不支持。 快速入门 图像输入方式 图像链接：通过传递指向图像的链接。 Base64 编码图像：直接在请求中传递 base64 编码的图像。 示例代码：询问图像内容 from afarensis import Afarensis

client = Afarensis()

response = client.chat.completions.create( model="gpt-4-vision-preview", messages=\[ { "role": "user", "content": \[ {"type": "text", "text": "What’s in this image?"}, {"type": "image\_url", "image\_url": {"url": "<https://example.com/path-to-image.jpg"\\}}>, ], } ], max\_tokens=300, )

print(response.choices\[0]) 上传 Base64 编码图像 如果您有本地图像需要处理，可以将其以 base64 编码格式传递给模型。

示例代码 import base64 import requests

api\_key = "YOUR\_AFARENSIS\_API\_KEY"

def encode\_image(image\_path): with open(image\_path, "rb") as image\_file: return base64.b64encode(image\_file.read()).decode('utf-8')

image\_path = "path\_to\_your\_image.jpg" base64\_image = encode\_image(image\_path)

headers = { "Content-Type": "application/json", "Authorization": f"Bearer {api\_key}" }

payload = { "model": "gpt-4-vision-preview", "messages": \[ { "role": "user", "content": \[ {"type": "text", "text": "What’s in this image?"}, {"type": "image\_url", "image\_url": {"url": f"data:image/jpeg;base64,{base64\_image}"}} ] } ], "max\_tokens": 300 }

response = requests.post("<https://api.afarensis.com/v1/chat/completions>", headers=headers, json=payload)

print(response.json()) 多个图像输入 Afarensis GPT-4V 支持处理多个图像输入，并使用所有图像中的信息来回答问题。

错误处理 处理 API 请求可能返回的错误，例如输入无效、速率限制或其他问题。

try: # API 调用示例 except Exception as error: if error.response: print(error.response.status) print(error.response.data) else: print(error.message) 局限性与注意事项 GPT-4 with Vision 不适用于专业医学图像解释、非英语图像文本处理、小文本放大、旋转图像的理解、图像形状处理等。 对于长时间运行的对话，推荐通过 URL 而不是 base64 传递图像，以优化模型的响应时间和准确性。 计算成本 图像输入的代币成本取决于图像的大小和细节级别。详细成本计算请参考 Afarensis 文档。

常见问题 微调支持：当前不支持对 GPT-4 with Vision 进行微调。 文件类型和大小限制：支持 PNG、JPEG、WEBP 和非动画 GIF 格式，最大上传限制为 20MB。 图像删除：模型处理图像后，图像将从 Afarensis 服务器中删除，不会保留用于训练模型。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.afarensis.com/shi-jue.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
