openrouter 1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.1
2
+ Name: openrouter
3
+ Version: 1.0
4
+ Summary: Unofficial OpenRouter Chatbot AI Library
5
+ Author: vboxvm512
6
+ Author-email: vboxvm512@gmail.com
7
+ License: MIT
8
+ Platform: any
9
+ Requires-Dist: requests
10
+ Requires-Dist: urllib3
11
+
12
+ README.md
@@ -0,0 +1,32 @@
1
+ openrouter library
2
+ ```bash
3
+ pip install openrouter
4
+ ```
5
+
6
+ Use Library
7
+ ```python
8
+ from openrouter.openrouter import Openrouter
9
+ from openrouter.openrouter import models
10
+ from openrouter.openrouter import roles
11
+ router = Openrouter(models.openai.gpt4o_mini,system_prompt="You are Persian Assistant")
12
+ ```
13
+ get and save messages to json file
14
+ ```python
15
+ #save to File
16
+ router.export_messages_to_file("msg.json",router.get_messages())
17
+
18
+ #append answer or question to messages
19
+ #as user
20
+ router.append_messages(roles.USER,"Questuin")
21
+ #as robot response
22
+ router.append_messages(roles.ASSISTANT,"Bot Response")
23
+
24
+ #get messages
25
+ print(router.get_messages())
26
+
27
+ #clear messages
28
+ router.clear_messages()
29
+
30
+ #set messages to session from file
31
+ router.set_messages(router.get_messages_from_file("msg.json"))
32
+ ```
File without changes
@@ -0,0 +1,90 @@
1
+ from requests import post
2
+ import json
3
+ import ast
4
+
5
+ print("Note : if you not set model in Openrouter function, this default value will be set to claude instant 1.1")
6
+ class roles:
7
+ USER="user"
8
+ SYSTEM="system"
9
+ ASSISTANT="assistant"
10
+
11
+ class models:
12
+ class openai:
13
+ gpt35_turbo="openai/gpt-3.5-turbo"
14
+ gpt4o_mini = "openai/gpt-4o-mini-2024-07-18"
15
+ class meta_llama:
16
+ llama_31 = "meta-llama/llama-3.1-8b-instruct"
17
+ class mistral:
18
+ nemo = "aetherwiing/mn-starcannon-12b"
19
+ class anthropic:
20
+ claude_instant = "anthropic/claude-instant-1.1"
21
+ class openchat:
22
+ b7_free="openchat/openchat-7b:free"
23
+ class google:
24
+ palm2_code = "google/palm-2-codechat-bison"
25
+
26
+
27
+ class Openrouter:
28
+ def __init__(self,model="anthropic/claude-instant-1.1",system_prompt="You Are UseFull Assistant"):
29
+ self.model = model
30
+ self.system_prompt = system_prompt
31
+ self.messages = [{"role":"system","content":system_prompt}]
32
+ def append_messages(self,role,content):
33
+ self.messages.extend([{'role':role,'content':content}])
34
+ def get_messages(self):
35
+ return self.messages
36
+ def get_messages_from_file(self,file):
37
+ file=open(file,"r")
38
+ content = file.read()
39
+ file.close()
40
+ return json.loads(json.dumps(content))
41
+ def export_messages_to_file(self,file,messages):
42
+ file=open(file,"w")
43
+ file.write(str(messages))
44
+ file.close()
45
+ def set_messages(self,jsondict):
46
+ self.messages = ast.literal_eval(jsondict)
47
+ def clear_messages(self):
48
+ self.messages = [{"role":"system","content":self.system_prompt}]
49
+ def ask_stream(self,text):
50
+ model = self.model
51
+ api="https://openrouter.ai/api/v1/chat/completions"
52
+ head = {
53
+ "authority": "openrouter.ai",
54
+ "method": "POST",
55
+ "path": "/api/v1/chat/completions",
56
+ "scheme": "https",
57
+
58
+ "Accept": "*/*",
59
+ "Accept-Encoding": "gzip, deflate, br, zstd",
60
+ "Accept-Language": "en-US,en;q=0.9",
61
+ "Baggage": "sentry-environment=vercel-production,sentry-release=7848d4dafe54b9a7a9459a871ee13afcb151f734,sentry-public_key=0ed8429ba9964f3fbba5d6f092ed2c8a,sentry-trace_id=0aaf3eb80b57494490abb7a87300fc3d,sentry-sample_rate=0.01,sentry-sampled=false",
62
+ "Content-Length": "113",
63
+ "Content-Type": "text/plain;charset=UTF-8",
64
+ "Http-Referer": "https://openrouter.ai/chat",
65
+ "Origin": "https://openrouter.ai",
66
+ "Priority": "u=1, i",
67
+ "Referer": "https://openrouter.ai/chat",
68
+ "Sec-Ch-Ua": "\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\", \"Google Chrome\";v=\"126\"",
69
+ "Sec-Ch-Ua-Mobile": "?0",
70
+ "Sec-Ch-Ua-Platform": "\"Windows\"",
71
+ "Sec-Fetch-Dest": "empty",
72
+ "Sec-Fetch-Mode": "cors",
73
+ "Sec-Fetch-Site": "same-origin",
74
+ "Sentry-Trace": "0aaf3eb80b57494490abb7a87300fc3d-bb6336568fedfc19-0",
75
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
76
+ "X-Title": "OpenRouter: Chatroom",
77
+ "Cookie":"_ga=GA1.1.2094209149.1723032142; __stripe_mid=237f6f99-4d4d-4049-8de0-2ec8d90003998696b4; __stripe_sid=c6c218c0-4271-4fe2-93b8-66f2ced7b6b6e134aa; __client_uat=1723032253; _ga_R8YZRJS2XN=GS1.1.1723032141.1.1.1723033557.0.0.0; __session_NO6jtgZM=eyJhbGciOiJSUzI1NiIsImNhdCI6ImNsX0I3ZDRQRDExMUFBQSIsImtpZCI6Imluc18yUGlRcWt2UlFlZXB3R3ZrVjFZRDhBb3Q1elIiLCJ0eXAiOiJKV1QifQ.eyJhenAiOiJodHRwczovL29wZW5yb3V0ZXIuYWkiLCJleHAiOjE3MjMwMzM1NzgsImlhdCI6MTcyMzAzMzUxOCwiaXNzIjoiaHR0cHM6Ly9jbGVyay5vcGVucm91dGVyLmFpIiwibmJmIjoxNzIzMDMzNTA4LCJzaWQiOiJzZXNzXzJrS1ZTTjZkUzFXY1pGY0NVbko4SFB1cWxEeSIsInN1YiI6InVzZXJfMml2bzZSSVJQQTdLTE05MmVxSEd0eFZ0MEdEIn0.b1KEyx5pJ4I9kQpjTAiAAEaN_zoVbe2oiixnLXi1U6mXY4Rb3UTHK5t7LRekD2A__kIpKQYoXMAKvGqv34fj0EihN3UgF0uhFz4XP2XghbrzcymlNOY3rHPsn9rcUFcRc58LMzxfxlOzrdy5jZ89bBm3EZ_ysyeD7wESNT30QF-l9hfvaQgYtTraYLhR1u3mCrqOn3Px9KlrVmtlgI1DgkWD8UNfz9N5sdDvV_2TEdOn3eh8H_jK4t2spP5cCc-Zeu1JMucmng64vvsXXhkC1QkUWmABtbWI0OPhfEQ3RFGxwCXRMoCAc4oaXgHboV6RQ-3NgbDzEJAFvRW8a2cHpg; __session=eyJhbGciOiJSUzI1NiIsImNhdCI6ImNsX0I3ZDRQRDExMUFBQSIsImtpZCI6Imluc18yUGlRcWt2UlFlZXB3R3ZrVjFZRDhBb3Q1elIiLCJ0eXAiOiJKV1QifQ.eyJhenAiOiJodHRwczovL29wZW5yb3V0ZXIuYWkiLCJleHAiOjE3MjMwMzM1NzgsImlhdCI6MTcyMzAzMzUxOCwiaXNzIjoiaHR0cHM6Ly9jbGVyay5vcGVucm91dGVyLmFpIiwibmJmIjoxNzIzMDMzNTA4LCJzaWQiOiJzZXNzXzJrS1ZTTjZkUzFXY1pGY0NVbko4SFB1cWxEeSIsInN1YiI6InVzZXJfMml2bzZSSVJQQTdLTE05MmVxSEd0eFZ0MEdEIn0.b1KEyx5pJ4I9kQpjTAiAAEaN_zoVbe2oiixnLXi1U6mXY4Rb3UTHK5t7LRekD2A__kIpKQYoXMAKvGqv34fj0EihN3UgF0uhFz4XP2XghbrzcymlNOY3rHPsn9rcUFcRc58LMzxfxlOzrdy5jZ89bBm3EZ_ysyeD7wESNT30QF-l9hfvaQgYtTraYLhR1u3mCrqOn3Px9KlrVmtlgI1DgkWD8UNfz9N5sdDvV_2TEdOn3eh8H_jK4t2spP5cCc-Zeu1JMucmng64vvsXXhkC1QkUWmABtbWI0OPhfEQ3RFGxwCXRMoCAc4oaXgHboV6RQ-3NgbDzEJAFvRW8a2cHpg"
78
+ }
79
+ true=True
80
+ false=False
81
+ data = {"stream":true,"model":model,"messages":self.get_messages(),"max_tokens":0}
82
+ stream = post(api,json=data,headers=head,stream=True)
83
+ for chunk in stream.iter_lines():
84
+ if chunk:
85
+ try:
86
+ get = chunk.decode().replace("data: ","")
87
+ yield json.loads(get)["choices"][0]["delta"]["content"]
88
+ except:
89
+ pass
90
+
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.1
2
+ Name: openrouter
3
+ Version: 1.0
4
+ Summary: Unofficial OpenRouter Chatbot AI Library
5
+ Author: vboxvm512
6
+ Author-email: vboxvm512@gmail.com
7
+ License: MIT
8
+ Platform: any
9
+ Requires-Dist: requests
10
+ Requires-Dist: urllib3
11
+
12
+ README.md
@@ -0,0 +1,10 @@
1
+ README.md
2
+ setup.py
3
+ openrouter/__init__.py
4
+ openrouter/openrouter.py
5
+ openrouter.egg-info/PKG-INFO
6
+ openrouter.egg-info/SOURCES.txt
7
+ openrouter.egg-info/dependency_links.txt
8
+ openrouter.egg-info/not-zip-safe
9
+ openrouter.egg-info/requires.txt
10
+ openrouter.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ requests
2
+ urllib3
@@ -0,0 +1 @@
1
+ openrouter
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ from setuptools import setup, find_packages
3
+
4
+
5
+ setup(
6
+ name='openrouter',
7
+ version='1.0',
8
+ packages=find_packages(),
9
+ license='MIT',
10
+ author='vboxvm512',
11
+ author_email='vboxvm512@gmail.com',
12
+ description='Unofficial OpenRouter Chatbot AI Library',
13
+ long_description="README.md",
14
+ zip_safe=False,
15
+ include_package_data=True,
16
+ platforms='any',
17
+ install_requires=[
18
+ 'requests',
19
+ 'urllib3'
20
+ ]
21
+ )