meshagent-openai 0.0.28__py3-none-any.whl → 0.0.30__py3-none-any.whl
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.
Potentially problematic release.
This version of meshagent-openai might be problematic. Click here for more details.
- meshagent/openai/proxy/__init__.py +1 -0
- meshagent/openai/proxy/proxy.py +31 -0
- meshagent/openai/tools/stt.py +90 -0
- meshagent/openai/version.py +1 -1
- {meshagent_openai-0.0.28.dist-info → meshagent_openai-0.0.30.dist-info}/METADATA +4 -4
- meshagent_openai-0.0.30.dist-info/RECORD +13 -0
- meshagent_openai-0.0.28.dist-info/RECORD +0 -10
- {meshagent_openai-0.0.28.dist-info → meshagent_openai-0.0.30.dist-info}/WHEEL +0 -0
- {meshagent_openai-0.0.28.dist-info → meshagent_openai-0.0.30.dist-info}/licenses/LICENSE +0 -0
- {meshagent_openai-0.0.28.dist-info → meshagent_openai-0.0.30.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .proxy import get_client
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from meshagent.api import RoomClient
|
|
3
|
+
from openai import AsyncOpenAI
|
|
4
|
+
|
|
5
|
+
def get_client(*, room: RoomClient) -> AsyncOpenAI:
|
|
6
|
+
|
|
7
|
+
if os.getenv("MESHAGENT_API_URL") == None:
|
|
8
|
+
token : str = room.protocol.token
|
|
9
|
+
url : str = room.room_url
|
|
10
|
+
|
|
11
|
+
room_proxy_url = f"{url}/v1"
|
|
12
|
+
if room_proxy_url.startswith("ws:") or room_proxy_url.startswith("wss:"):
|
|
13
|
+
room_proxy_url = room_proxy_url.replace("ws","http",1)
|
|
14
|
+
|
|
15
|
+
openai=AsyncOpenAI(
|
|
16
|
+
api_key=token,
|
|
17
|
+
base_url=room_proxy_url,
|
|
18
|
+
default_headers={
|
|
19
|
+
"Meshagent-Session" : room.session_id
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
else:
|
|
24
|
+
|
|
25
|
+
openai=AsyncOpenAI(
|
|
26
|
+
default_headers={
|
|
27
|
+
"Meshagent-Session" : room.session_id
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
return openai
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from meshagent.tools import ToolContext, Tool, Toolkit, JsonResponse, TextResponse
|
|
2
|
+
from openai import AsyncOpenAI
|
|
3
|
+
from meshagent.openai.proxy import get_client
|
|
4
|
+
from typing import Optional
|
|
5
|
+
import io
|
|
6
|
+
import pathlib
|
|
7
|
+
|
|
8
|
+
from meshagent.openai.proxy import get_client
|
|
9
|
+
|
|
10
|
+
async def _transcribe(*, client: AsyncOpenAI, data: bytes, model: str, filename: str, response_format: str, timestamp_granularities: list[str] = None, prompt: Optional[str] = None, language: Optional[str] = None):
|
|
11
|
+
|
|
12
|
+
buf = io.BytesIO(data)
|
|
13
|
+
buf.name = filename
|
|
14
|
+
transcript = await client.audio.transcriptions.create(
|
|
15
|
+
model=model,
|
|
16
|
+
response_format=response_format,
|
|
17
|
+
file=buf,
|
|
18
|
+
prompt=prompt,
|
|
19
|
+
language=language,
|
|
20
|
+
timestamp_granularities=timestamp_granularities,
|
|
21
|
+
stream=False
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
if isinstance(transcript, str):
|
|
25
|
+
return TextResponse(text=transcript)
|
|
26
|
+
|
|
27
|
+
return JsonResponse(json=transcript.to_dict(mode="json"))
|
|
28
|
+
|
|
29
|
+
class OpenAIAudioFileSTT(Tool):
|
|
30
|
+
def __init__(self, *, client: Optional[AsyncOpenAI] = None):
|
|
31
|
+
super().__init__(
|
|
32
|
+
name="openai-file-stt",
|
|
33
|
+
input_schema={
|
|
34
|
+
"type" : "object",
|
|
35
|
+
"additionalProperties" : False,
|
|
36
|
+
"required" : [ "model", "path", "response_format", "timestamp_granularities", "prompt"],
|
|
37
|
+
"properties" : {
|
|
38
|
+
"path" : {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"description" : "the path to a file in the room storage",
|
|
41
|
+
},
|
|
42
|
+
"prompt" : {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"description" : "a prompt. can improve the accuracy of the transcript",
|
|
45
|
+
},
|
|
46
|
+
"model" : {
|
|
47
|
+
"type" : "string",
|
|
48
|
+
"enum" : [
|
|
49
|
+
"whisper-1", "gpt-4o-mini-transcribe", "gpt-4o-transcribe"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"response_format" : {
|
|
53
|
+
"type" : "string",
|
|
54
|
+
"description" : "text and json are supported for all models, srt, verbose_json, and vtt are only supported for whisper-1",
|
|
55
|
+
"enum" : [ "text", "json", "srt", "verbose_json", "vtt" ]
|
|
56
|
+
},
|
|
57
|
+
"timestamp_granularities" : {
|
|
58
|
+
"description" : "timestamp_granularities are only valid with whisper-1",
|
|
59
|
+
"type" : "array",
|
|
60
|
+
"items" : {
|
|
61
|
+
"type" : "string",
|
|
62
|
+
"enum" : [ "word", "segment" ]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
title="OpenAI audio file STT",
|
|
68
|
+
description="transcribes an audio file to text"
|
|
69
|
+
)
|
|
70
|
+
self.client = client
|
|
71
|
+
|
|
72
|
+
async def execute(self, context: ToolContext, *, model: str, prompt: str, path: str, response_format: str, timestamp_granularities: list):
|
|
73
|
+
|
|
74
|
+
file_data = await context.room.storage.download(path=path)
|
|
75
|
+
client = self.client
|
|
76
|
+
if client == None:
|
|
77
|
+
client = get_client(room=context.room)
|
|
78
|
+
|
|
79
|
+
return await _transcribe(client=client, data=file_data.data, model=model, prompt=prompt, filename=pathlib.Path(path).name, response_format=response_format)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class OpenAISTTToolkit(Toolkit):
|
|
83
|
+
def __init__(self):
|
|
84
|
+
super().__init__(
|
|
85
|
+
name="openai-stt",
|
|
86
|
+
description="tools for speech to text using openai",
|
|
87
|
+
tools=[
|
|
88
|
+
OpenAIAudioFileSTT()
|
|
89
|
+
]
|
|
90
|
+
)
|
meshagent/openai/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.0.
|
|
1
|
+
__version__ = "0.0.30"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: meshagent-openai
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.30
|
|
4
4
|
Summary: OpenAI Building Blocks for Meshagent
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
Project-URL: Documentation, https://docs.meshagent.com
|
|
@@ -13,9 +13,9 @@ Requires-Dist: pyjwt~=2.10.1
|
|
|
13
13
|
Requires-Dist: pytest~=8.3.5
|
|
14
14
|
Requires-Dist: pytest-asyncio~=0.26.0
|
|
15
15
|
Requires-Dist: openai~=1.70.0
|
|
16
|
-
Requires-Dist: meshagent-api~=0.0.
|
|
17
|
-
Requires-Dist: meshagent-agents~=0.0.
|
|
18
|
-
Requires-Dist: meshagent-tools~=0.0.
|
|
16
|
+
Requires-Dist: meshagent-api~=0.0.30
|
|
17
|
+
Requires-Dist: meshagent-agents~=0.0.30
|
|
18
|
+
Requires-Dist: meshagent-tools~=0.0.30
|
|
19
19
|
Dynamic: license-file
|
|
20
20
|
|
|
21
21
|
### Meshagent OpenAI
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
meshagent/openai/__init__.py,sha256=4JRby-ltGfJzrNYhJkMNIpVc2ml2zL_JkkFC0T1_8Vk,174
|
|
2
|
+
meshagent/openai/version.py,sha256=Ji8g_yOyFfpoV8jQQPNpvlINEqW1-F23R31bqwShK9o,22
|
|
3
|
+
meshagent/openai/proxy/__init__.py,sha256=SqoueAmMXHbDKd8O4EeqGkI0gEiC3xLTLlpESGxySPU,30
|
|
4
|
+
meshagent/openai/proxy/proxy.py,sha256=FBlFYVwBVorxif1hbYAG3fz-1J3_XPogpBIHS_OGRW0,822
|
|
5
|
+
meshagent/openai/tools/__init__.py,sha256=RBU_J4qRDuBaaUdi6jpgpuMlIbvT30QmTBrZrYLwsUU,185
|
|
6
|
+
meshagent/openai/tools/completions_adapter.py,sha256=4xEfs57O5GrIRnz1_yVRd3nJpC521lMKFO7RANczRnw,15191
|
|
7
|
+
meshagent/openai/tools/responses_adapter.py,sha256=QdTnnSvsGK0nMgceEX-kwo1lAc59ot7G1CYre-n6aFM,23390
|
|
8
|
+
meshagent/openai/tools/stt.py,sha256=qMuzkOss7Z5zRVsxmZRASugfgsvuWMG3_6toezq68s8,3612
|
|
9
|
+
meshagent_openai-0.0.30.dist-info/licenses/LICENSE,sha256=eTt0SPW-sVNdkZe9PS_S8WfCIyLjRXRl7sUBWdlteFg,10254
|
|
10
|
+
meshagent_openai-0.0.30.dist-info/METADATA,sha256=XQb4qd9uTDHuHGJnuvt2Cp3oJ8lgx0xJZWWvrdhFlUg,660
|
|
11
|
+
meshagent_openai-0.0.30.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
meshagent_openai-0.0.30.dist-info/top_level.txt,sha256=GlcXnHtRP6m7zlG3Df04M35OsHtNXy_DY09oFwWrH74,10
|
|
13
|
+
meshagent_openai-0.0.30.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
meshagent/openai/__init__.py,sha256=4JRby-ltGfJzrNYhJkMNIpVc2ml2zL_JkkFC0T1_8Vk,174
|
|
2
|
-
meshagent/openai/version.py,sha256=mzuLWOw_MsO0PILYQa7qjrIQ5hlmZ-M3dVvx0CP5QkY,22
|
|
3
|
-
meshagent/openai/tools/__init__.py,sha256=RBU_J4qRDuBaaUdi6jpgpuMlIbvT30QmTBrZrYLwsUU,185
|
|
4
|
-
meshagent/openai/tools/completions_adapter.py,sha256=4xEfs57O5GrIRnz1_yVRd3nJpC521lMKFO7RANczRnw,15191
|
|
5
|
-
meshagent/openai/tools/responses_adapter.py,sha256=QdTnnSvsGK0nMgceEX-kwo1lAc59ot7G1CYre-n6aFM,23390
|
|
6
|
-
meshagent_openai-0.0.28.dist-info/licenses/LICENSE,sha256=eTt0SPW-sVNdkZe9PS_S8WfCIyLjRXRl7sUBWdlteFg,10254
|
|
7
|
-
meshagent_openai-0.0.28.dist-info/METADATA,sha256=CYfrtniUyjxiq0D05w7zMf3FrOY8SDwIWZiEQcQoT7g,660
|
|
8
|
-
meshagent_openai-0.0.28.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
-
meshagent_openai-0.0.28.dist-info/top_level.txt,sha256=GlcXnHtRP6m7zlG3Df04M35OsHtNXy_DY09oFwWrH74,10
|
|
10
|
-
meshagent_openai-0.0.28.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|