怎么给api加上prompt?

one api里面好像不能

1 个赞

oneapi 只是做转发的网关,你api调用的时候自己加上就好.

1 个赞

在请求的时候,加上prompt就可以了

1 个赞
def api_request(text):
        
        # 定义你的提示
        prompt = "You are AI..."

        # 将提示与实际文本合并
        full_text = prompt + text
        text =  " "
        headers = {
            "Authorization": f"Bearer {OPENAI_API_KEY}",
            "Content-Type": "application/json"
        }
        data = {
            'model': 'gpt-4',
            'messages': [{'role': 'user', 'content': full_text}]
        }
        url = 'https://sample.com/v1/chat/completions'

        try:
            response = requests.post(url, headers=headers, data=json.dumps(data))
                  
1 个赞

或者用system:

def api_request(text):
        
        # 定义你的提示
        prompt = "You are AI..."

        text =  " "
        headers = {
            "Authorization": f"Bearer {OPENAI_API_KEY}",
            "Content-Type": "application/json"
        }
        data = {
            'model': 'gpt-4',
            'messages': [{'role': 'system', 'content': prompt}, {'role': 'user', 'content': text}]
        }
        url = 'https://sample.com/v1/chat/completions'

        try:
            response = requests.post(url, headers=headers, data=json.dumps(data))
2 个赞

楼上正解。不过一般商业api或者逆向的api是不支持改变system prompt的。直接在第一个user的input里面写就可以。

2 个赞