记录来自截获的 OpenAI 兼容请求和响应的 OpenAI 遥测数据。
插件实例定义
{
"name": "OpenAITelemetryPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
"configSection": "openAITelemetryPlugin"
}
配置示例
{
"openAITelemetryPlugin": {
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/openaitelemetryplugin.schema.json",
"application": "My app",
"includeCosts": true,
"pricesFile": "prices.json"
}
}
配置属性
资产 | DESCRIPTION | 违约 |
---|---|---|
application |
发出请求的应用程序的名称。 记录在遥测数据中,按应用程序对使用情况进行分组。 | default |
currency |
记录价格的货币。 显示在图表中。 | USD |
environment |
运行应用程序的环境。 记录在遥测数据中,按环境对使用情况进行分组。 | development |
exporterEndpoint |
要向其发送数据的 OpenTelemetry 终结点的 URL。 必须是 HTTP Protobuf 终结点。 | http://localhost:4318 |
includeCompletion |
是否在遥测数据中包含完成。 | true |
includeCosts |
是否在遥测数据中包含成本。 需要指定价格文件。 | false |
includePrompt |
是否在遥测数据中包含提示。 | true |
pricesFile |
包含价格信息的文件的路径。 | null |
价格文件示例
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/openaitelemetryplugin.pricesfile.schema.json",
"prices": {
"gpt-3.5-turbo": {
"input": 0.0015,
"output": 0.002
},
"gpt-4": {
"input": 0.03,
"output": 0.06
}
}
}
价格文件属性
资产 | DESCRIPTION | 违约 |
---|---|---|
prices |
模型的价格。 键是模型名称,值为模型价格对象。 | {} |
模型价格对象
每个模型价格对象具有以下属性:
资产 | DESCRIPTION | 必选 | 默认值 | 示例值 |
---|---|---|---|---|
input |
输入/提示令牌每百万个令牌的价格。 | 是的 | 0.0 |
0.03 |
output |
输出/完成令牌每百万个令牌的价格。 | 是的 | 0.0 |
0.06 |
命令行选项
没有
注解
OpenAITelemetryPlugin 记录与 OpenAI 兼容的请求和它截获的响应中的 OpenTelemetry 数据。 无需使用 OpenTelemetry 检测应用程序,即可快速了解应用程序如何使用大型语言模型。 此外,如果为所使用的模型提供价格文件,还可以查看应用程序产生的与 LLM 相关的成本。
对于每个截获的请求和响应,插件会记录范围。 此外,它还记录了三个指标:
-
gen_ai.client.token.usage
- 请求和响应中使用的令牌数 -
gen_ai.usage.cost
- 请求和响应中使用的令牌的成本 -
gen_ai.usage.total_cost
- 会话过程中所有请求的总成本
重要
仅当将 includeCosts
属性 true
设置为并提供价格文件时,才会记录成本指标。 否则,插件不会记录指标。
若要查看记录的遥测数据,可以使用任何与 OpenTelemetry 兼容的仪表板。 例如,可以使用 .NET Aspire 仪表板 或 OpenLIT。
重要
若要查看数据,请在发出与 OpenAI 兼容的请求之前启动仪表板。 否则,没有 OpenTelemetry 收集器接收插件发送的数据。