用openAI API来分析log

API: openAI API (pip 安装openai 包)

AI模型:通义千问(需要开通百炼服务)

利用大模型来阅读和分析log

from pathlib import Path
import os
from openai import OpenAI

def clean_file():
    client = OpenAI(
        api_key=os.getenv("DASHSCOPE_API_KEY"),
        base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    )
    files = client.files.list()
    print(files)
    for file in files.data:
        client.files.delete(file.id)

def get_response():
    client = OpenAI(
        api_key=os.getenv("DASHSCOPE_API_KEY"),
        base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    )


    # data.pdf 是一个示例文件
    file_object_main = client.files.create(file=Path("log1.txt"), purpose="file-extract")
    file_object_phy = client.files.create(file=Path("log2.txt"), purpose="file-extract")

    completion = client.chat.completions.create(
        model="qwen-long",
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "system", "content": f"fileid://{file_object_main.id}"},
            {"role": "system", "content": f"fileid://{file_object_phy.id}"},
            {"role": "user", "content": "请结合2份log上的时间戳,分析出错的原因。"},
            
        ],
    )
    client.files.delete(file_object_phy.id)
    client.files.delete(file_object_main.id)
    return completion.choices[0].message.content.strip()

if __name__ == '__main__':
    clean_file()
    response = get_response()
    print(response)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值