Skip to content

Commit 48e6531

Browse files
committed
[0.5.7] chore
1 parent bfe0793 commit 48e6531

File tree

10 files changed

+28
-4
lines changed

10 files changed

+28
-4
lines changed

docs/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ minor versions.
77

88
All relevant steps to be taken will be mentioned here.
99

10+
0.5.7
11+
-----
12+
13+
- Implement ``extra_headers`` via ``__init__`` as well.
14+
1015
0.5.6
1116
-----
1217

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
project = "tuneapi"
1414
copyright = "2024, Frello Technologies"
1515
author = "Frello Technologies"
16-
release = "0.5.6"
16+
release = "0.5.7"
1717

1818
# -- General configuration ---------------------------------------------------
1919
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "tuneapi"
3-
version = "0.5.6"
3+
version = "0.5.7"
44
description = "Tune AI APIs."
55
authors = ["Frello Technology Private Limited <[email protected]>"]
66
license = "MIT"

tuneapi/apis/model_anthropic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ def __init__(
1818
self,
1919
id: Optional[str] = "claude-3-haiku-20240307",
2020
base_url: str = "https://api.anthropic.com/v1/messages",
21+
extra_headers: Optional[Dict[str, str]] = None,
2122
):
2223
self.model_id = id
2324
self.base_url = base_url
2425
self.api_token = tu.ENV.ANTHROPIC_TOKEN("")
26+
self.extra_headers = extra_headers
2527

2628
def set_api_token(self, token: str) -> None:
2729
self.api_token = token
@@ -159,6 +161,7 @@ def stream_chat(
159161
for t in tools:
160162
t["input_schema"] = t.pop("parameters")
161163
headers, system, claude_messages = self._process_input(chats=chats, token=token)
164+
extra_headers = extra_headers or self.extra_headers
162165
if extra_headers:
163166
headers.update(extra_headers)
164167

tuneapi/apis/model_gemini.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ def __init__(
1818
self,
1919
id: Optional[str] = "gemini-1.5-pro-latest",
2020
base_url: str = "https://generativelanguage.googleapis.com/v1beta/models/{id}:{rpc}",
21+
extra_headers: Optional[Dict[str, str]] = None,
2122
):
2223
self.model_id = id
2324
self.base_url = base_url
2425
self.api_token = tu.ENV.GEMINI_TOKEN("")
26+
self.extra_headers = extra_headers
2527

2628
def set_api_token(self, token: str) -> None:
2729
self.api_token = token
@@ -152,6 +154,7 @@ def stream_chat(
152154
if isinstance(chats, tt.Thread):
153155
tools = [x.to_dict() for x in chats.tools]
154156
headers, system, messages, params = self._process_input(chats, token)
157+
extra_headers = extra_headers or self.extra_headers
155158
if extra_headers:
156159
headers.update(extra_headers)
157160
data = {

tuneapi/apis/model_groq.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ def __init__(
1717
self,
1818
id: Optional[str] = "llama3-70b-8192",
1919
base_url: str = "https://api.groq.com/openai/v1/chat/completions",
20+
extra_headers: Optional[Dict[str, str]] = None,
2021
):
2122
self.model_id = id
2223
self.base_url = base_url
2324
self.api_token = tu.ENV.GROQ_TOKEN("")
25+
self.extra_headers = extra_headers
2426

2527
def set_api_token(self, token: str) -> None:
2628
self.api_token = token
@@ -133,6 +135,7 @@ def stream_chat(
133135
if isinstance(chats, tt.Thread):
134136
tools = [{"type": "function", "function": x.to_dict()} for x in chats.tools]
135137
headers, messages = self._process_input(chats, token)
138+
extra_headers = extra_headers or self.extra_headers
136139
if extra_headers:
137140
headers.update(extra_headers)
138141
data = {

tuneapi/apis/model_mistral.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ def __init__(
1919
self,
2020
id: Optional[str] = "mistral-small-latest",
2121
base_url: str = "https://api.mistral.ai/v1/chat/completions",
22+
extra_headers: Optional[Dict[str, str]] = None,
2223
):
2324
self.model_id = id
2425
self.base_url = base_url
2526
self.api_token = ENV.MISTRAL_TOKEN("")
27+
self.extra_headers = extra_headers
2628

2729
def set_api_token(self, token: str) -> None:
2830
self.api_token = token
@@ -136,6 +138,7 @@ def stream_chat(
136138
if isinstance(chats, Thread):
137139
tools = [{"type": "function", "function": x.to_dict()} for x in chats.tools]
138140
headers, messages = self._process_input(chats, token)
141+
extra_headers = extra_headers or self.extra_headers
139142
if extra_headers:
140143
headers.update(extra_headers)
141144
data = {

tuneapi/apis/model_openai.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ def __init__(
1818
self,
1919
id: Optional[str] = "gpt-4o",
2020
base_url: str = "https://api.openai.com/v1/chat/completions",
21+
extra_headers: Optional[Dict[str, str]] = None,
2122
):
2223
self.model_id = id
2324
self.base_url = base_url
2425
self.api_token = tu.ENV.OPENAI_TOKEN("")
26+
self.extra_headers = extra_headers
2527

2628
def set_api_token(self, token: str) -> None:
2729
self.api_token = token
@@ -131,6 +133,7 @@ def stream_chat(
131133
raw: bool = False,
132134
):
133135
headers, messages = self._process_input(chats, token)
136+
extra_headers = extra_headers or self.extra_headers
134137
if extra_headers:
135138
headers.update(extra_headers)
136139
data = {
@@ -187,8 +190,6 @@ def stream_chat(
187190
yield fn_call
188191
return
189192

190-
# def _process_chat_to_string_for_embedding(self, chat: tt.Thread):
191-
192193
def embedding(
193194
self,
194195
chats: tt.Thread | List[str] | str,
@@ -203,6 +204,7 @@ def embedding(
203204
text = []
204205

205206
headers = self._process_header(token)
207+
extra_headers = extra_headers or self.extra_headers
206208
if extra_headers:
207209
headers.update(extra_headers)
208210
if isinstance(chats, tt.Thread):

tuneapi/apis/model_tune.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ def __init__(
2121
base_url: str = "https://proxy.tune.app/chat/completions",
2222
api_token: Optional[str] = None,
2323
org_id: Optional[str] = None,
24+
extra_headers: Optional[Dict[str, str]] = None,
2425
):
2526
self.model_id = id or tu.ENV.TUNEAPI_MODEL("")
2627
self.base_url = base_url
2728
self.api_token = api_token or tu.ENV.TUNEAPI_TOKEN("")
2829
self.org_id = org_id or tu.ENV.TUNEORG_ID("")
30+
self.extra_headers = extra_headers
2931

3032
def __repr__(self) -> str:
3133
out = f"<TuneModel: {self.model_id}"
@@ -156,6 +158,7 @@ def stream_chat(
156158
"Tune Model ID not found. Please set TUNEAPI_MODEL environment variable or pass through function"
157159
)
158160
headers, messages = self._process_input(chats, token)
161+
extra_headers = extra_headers or self.extra_headers
159162
if extra_headers:
160163
headers.update(extra_headers)
161164
data = {

tuneapi/types/chats.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def chat(
321321
temperature: float = 1,
322322
token: Optional[str] = None,
323323
timeout=(5, 30),
324+
extra_headers: Optional[Dict[str, str]] = None,
324325
**kwargs,
325326
) -> str | Dict[str, Any]:
326327
"""This is the main function to block chat with the model"""
@@ -335,6 +336,7 @@ def stream_chat(
335336
timeout=(5, 60),
336337
raw: bool = False,
337338
debug: bool = False,
339+
extra_headers: Optional[Dict[str, str]] = None,
338340
):
339341
"""This is the main function to stream chat with the model where each token is iteratively generated"""
340342

0 commit comments

Comments
 (0)