File size: 1,278 Bytes
ef4248d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

import openai
import requests

class MultiAIChat:
    def __init__(self, openai_key, huggingface_key, anthropic_key):
        self.openai_key = openai_key
        self.huggingface_key = huggingface_key
        self.anthropic_key = anthropic_key

    def openai_chat(self, prompt):
        openai.api_key = self.openai_key
        response = openai.Completion.create(engine="text-davinci-003", prompt=prompt, max_tokens=100)
        return response.choices[0].text.strip()

    def huggingface_chat(self, prompt):
        url = "https://api-inference.huggingface.co/models/facebook/blenderbot-400M-distill"
        headers = {"Authorization": f"Bearer {self.huggingface_key}"}
        response = requests.post(url, json={"inputs": prompt}, headers=headers)
        return response.json().get("generated_text", "")

    def anthropic_chat(self, prompt):
        url = "https://api.anthropic.com/v1/completion"
        headers = {"Authorization": f"Bearer {self.anthropic_key}"}
        response = requests.post(url, json={"prompt": prompt, "model": "claude-v1"})
        return response.json().get("output", "")

if __name__ == "__main__":
    chat = MultiAIChat("openai_key", "huggingface_key", "anthropic_key")
    print(chat.openai_chat("Hello, how can I assist you today?"))