mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
3
.gitignore
vendored
3
.gitignore
vendored
@ -164,4 +164,5 @@ cython_debug/
|
|||||||
playground.py
|
playground.py
|
||||||
.env*
|
.env*
|
||||||
models
|
models
|
||||||
.idea/
|
.idea/
|
||||||
|
promtail/
|
||||||
@ -7,7 +7,7 @@ pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https
|
|||||||
```
|
```
|
||||||
## More Dependencies
|
## More Dependencies
|
||||||
| System | package | web | install command |
|
| System | package | web | install command |
|
||||||
| --- | | --- | --- |
|
| --- | ---- | --- | --- |
|
||||||
| python | filetype | https://pypi.org/project/filetype/ | pip install filetype |
|
| python | filetype | https://pypi.org/project/filetype/ | pip install filetype |
|
||||||
| python | fastAPI | https://fastapi.tiangolo.com/ | pip install fastapi |
|
| python | fastAPI | https://fastapi.tiangolo.com/ | pip install fastapi |
|
||||||
| python | python-multipart | https://pypi.org/project/python-multipart/ | pip install python-multipart |
|
| python | python-multipart | https://pypi.org/project/python-multipart/ | pip install python-multipart |
|
||||||
|
|||||||
20
main.py
20
main.py
@ -1,4 +1,22 @@
|
|||||||
import uvicorn
|
import uvicorn
|
||||||
|
import logging
|
||||||
|
from injector import Injector,inject
|
||||||
|
from src.log.handler import LogHandler
|
||||||
|
from src.configuration import EnvConf, LogConf, singleton
|
||||||
|
|
||||||
|
@singleton
|
||||||
|
class Main():
|
||||||
|
|
||||||
|
@inject
|
||||||
|
def __init__(self, logConf: LogConf) -> None:
|
||||||
|
logging.basicConfig(level=logConf.level,filename=logConf.filename,format="%(asctime)s %(levelname)s %(message)s")
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logger.info("jarvis-models start", extra={"version": "0.0.1"})
|
||||||
|
uvicorn.run("server:app", host="0.0.0.0", port=8001, log_level="info")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
uvicorn.run("router:app", host="0.0.0.0", port=8000, log_level="info")
|
injector = Injector()
|
||||||
|
main = injector.get(Main)
|
||||||
|
main.run()
|
||||||
7
requirements.txt
Normal file
7
requirements.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
filetype==1.2.0
|
||||||
|
fastapi==0.110.3
|
||||||
|
python-multipart==0.0.9
|
||||||
|
uvicorn==0.29.0
|
||||||
|
SpeechRecognition==3.10.3
|
||||||
|
PyYAML==6.0.1
|
||||||
|
injector==0.21.0
|
||||||
@ -1,13 +1,9 @@
|
|||||||
from typing import Annotated, Union
|
from typing import Union
|
||||||
|
|
||||||
from fastapi import FastAPI, Request, status, Form
|
from fastapi import FastAPI, Request, status
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
|
|
||||||
from src.dotchain.runtime.interpreter import program_parser
|
|
||||||
from src.dotchain.runtime.tokenizer import Tokenizer
|
|
||||||
from src.dotchain.runtime.runtime import Runtime
|
|
||||||
from src.blackbox.blackbox_factory import BlackboxFactory
|
from src.blackbox.blackbox_factory import BlackboxFactory
|
||||||
import uvicorn
|
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from injector import Injector
|
from injector import Injector
|
||||||
|
|
||||||
@ -29,7 +25,7 @@ async def blackbox(blackbox_name: Union[str, None] = None, request: Request = No
|
|||||||
if not blackbox_name:
|
if not blackbox_name:
|
||||||
return await JSONResponse(content={"error": "blackbox_name is required"}, status_code=status.HTTP_400_BAD_REQUEST)
|
return await JSONResponse(content={"error": "blackbox_name is required"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||||
try:
|
try:
|
||||||
box = blackbox_factory.call_blackbox(blackbox_name)
|
box = blackbox_factory.get_blackbox(blackbox_name)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return await JSONResponse(content={"error": "value error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
return await JSONResponse(content={"error": "value error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||||
return await box.fast_api_handler(request)
|
return await box.fast_api_handler(request)
|
||||||
@ -7,12 +7,13 @@ from fastapi.responses import JSONResponse
|
|||||||
from ..asr.rapid_paraformer.utils import read_yaml
|
from ..asr.rapid_paraformer.utils import read_yaml
|
||||||
from ..asr.rapid_paraformer import RapidParaformer
|
from ..asr.rapid_paraformer import RapidParaformer
|
||||||
from .blackbox import Blackbox
|
from .blackbox import Blackbox
|
||||||
from injector import singleton
|
from injector import singleton, inject
|
||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
class ASR(Blackbox):
|
class ASR(Blackbox):
|
||||||
|
|
||||||
def __init__(self, path = ".env.yaml") -> None:
|
@inject
|
||||||
|
def __init__(self,path = ".env.yaml") -> None:
|
||||||
config = read_yaml(path)
|
config = read_yaml(path)
|
||||||
self.paraformer = RapidParaformer(config)
|
self.paraformer = RapidParaformer(config)
|
||||||
|
|
||||||
@ -34,6 +35,7 @@ class ASR(Blackbox):
|
|||||||
async def fast_api_handler(self, request: Request) -> Response:
|
async def fast_api_handler(self, request: Request) -> Response:
|
||||||
data = (await request.form()).get("audio")
|
data = (await request.form()).get("audio")
|
||||||
if data is None:
|
if data is None:
|
||||||
|
self.logger.warn("asr bag request","type", "fast_api_handler", "api", "asr")
|
||||||
return JSONResponse(content={"error": "data is required"}, status_code=status.HTTP_400_BAD_REQUEST)
|
return JSONResponse(content={"error": "data is required"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||||
d = await data.read()
|
d = await data.read()
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
from fastapi import Request, Response,status
|
from fastapi import Request, Response,status
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from injector import inject, singleton
|
from injector import inject, singleton
|
||||||
@ -8,11 +9,14 @@ from .tts import TTS
|
|||||||
|
|
||||||
from .blackbox import Blackbox
|
from .blackbox import Blackbox
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
class AudioChat(Blackbox):
|
class AudioChat(Blackbox):
|
||||||
|
|
||||||
@inject
|
@inject
|
||||||
def __init__(self, asr: ASR, gpt: Tesou, tts: TTS):
|
def __init__(self, asr: ASR, gpt: Tesou, tts: TTS):
|
||||||
|
logger.info("audio chat initint")
|
||||||
self.asr = asr
|
self.asr = asr
|
||||||
self.gpt = gpt
|
self.gpt = gpt
|
||||||
self.tts = tts
|
self.tts = tts
|
||||||
|
|||||||
@ -3,16 +3,16 @@ from .sentiment import Sentiment
|
|||||||
from .tts import TTS
|
from .tts import TTS
|
||||||
from .asr import ASR
|
from .asr import ASR
|
||||||
from .audio_to_text import AudioToText
|
from .audio_to_text import AudioToText
|
||||||
from .emotion import Emotion
|
#from .emotion import Emotion
|
||||||
from .blackbox import Blackbox
|
from .blackbox import Blackbox
|
||||||
from .text_to_audio import TextToAudio
|
from .text_to_audio import TextToAudio
|
||||||
from .tesou import Tesou
|
from .tesou import Tesou
|
||||||
from .fastchat import Fastchat
|
from .fastchat import Fastchat
|
||||||
from .g2e import G2E
|
from .g2e import G2E
|
||||||
from .text_and_image import TextAndImage
|
from .text_and_image import TextAndImage
|
||||||
from .chroma_query import ChromaQuery
|
# from .chroma_query import ChromaQuery
|
||||||
from .chroma_upsert import ChromaUpsert
|
# from .chroma_upsert import ChromaUpsert
|
||||||
from .chroma_chat import ChromaChat
|
# from .chroma_chat import ChromaChat
|
||||||
from .melotts import MeloTTS
|
from .melotts import MeloTTS
|
||||||
from .vlms import VLMS
|
from .vlms import VLMS
|
||||||
from injector import inject, singleton
|
from injector import inject, singleton
|
||||||
@ -28,16 +28,15 @@ class BlackboxFactory:
|
|||||||
asr: ASR,
|
asr: ASR,
|
||||||
tts: TTS,
|
tts: TTS,
|
||||||
sentiment_engine: Sentiment,
|
sentiment_engine: Sentiment,
|
||||||
emotion: Emotion,
|
#emotion: Emotion,
|
||||||
tesou: Tesou,
|
tesou: Tesou,
|
||||||
fastchat: Fastchat,
|
fastchat: Fastchat,
|
||||||
audio_chat: AudioChat,
|
audio_chat: AudioChat,
|
||||||
g2e: G2E,
|
g2e: G2E,
|
||||||
text_and_image: TextAndImage,
|
text_and_image: TextAndImage,
|
||||||
chroma_query: ChromaQuery,
|
#chroma_query: ChromaQuery,
|
||||||
chroma_upsert: ChromaUpsert,
|
#chroma_upsert: ChromaUpsert,
|
||||||
chroma_chat: ChromaChat,
|
#chroma_chat: ChromaChat,
|
||||||
melotts: MeloTTS,
|
|
||||||
vlms: VLMS) -> None:
|
vlms: VLMS) -> None:
|
||||||
self.models["audio_to_text"] = audio_to_text
|
self.models["audio_to_text"] = audio_to_text
|
||||||
self.models["text_to_audio"] = text_to_audio
|
self.models["text_to_audio"] = text_to_audio
|
||||||
@ -45,21 +44,20 @@ class BlackboxFactory:
|
|||||||
self.models["tts"] = tts
|
self.models["tts"] = tts
|
||||||
self.models["sentiment_engine"] = sentiment_engine
|
self.models["sentiment_engine"] = sentiment_engine
|
||||||
self.models["tesou"] = tesou
|
self.models["tesou"] = tesou
|
||||||
self.models["emotion"] = emotion
|
#self.models["emotion"] = emotion
|
||||||
self.models["fastchat"] = fastchat
|
self.models["fastchat"] = fastchat
|
||||||
self.models["audio_chat"] = audio_chat
|
self.models["audio_chat"] = audio_chat
|
||||||
self.models["g2e"] = g2e
|
self.models["g2e"] = g2e
|
||||||
self.models["text_and_image"] = text_and_image
|
self.models["text_and_image"] = text_and_image
|
||||||
self.models["chroma_query"] = chroma_query
|
#self.models["chroma_query"] = chroma_query
|
||||||
self.models["chroma_upsert"] = chroma_upsert
|
#self.models["chroma_upsert"] = chroma_upsert
|
||||||
self.models["chroma_chat"] = chroma_chat
|
#self.models["chroma_chat"] = chroma_chat
|
||||||
self.models["melotts"] = melotts
|
|
||||||
self.models["vlms"] = vlms
|
self.models["vlms"] = vlms
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
return self.processing(*args, **kwargs)
|
return self.processing(*args, **kwargs)
|
||||||
|
|
||||||
def call_blackbox(self, blackbox_name: str) -> Blackbox:
|
def get_blackbox(self, blackbox_name: str) -> Blackbox:
|
||||||
model = self.models.get(blackbox_name)
|
model = self.models.get(blackbox_name)
|
||||||
if model is None:
|
if model is None:
|
||||||
raise ValueError("Invalid Blackbox Type...")
|
raise ValueError("Invalid Blackbox Type...")
|
||||||
|
|||||||
@ -57,4 +57,3 @@ class Emotion(Blackbox):
|
|||||||
text = [{'role': 'user', 'content': text}]
|
text = [{'role': 'user', 'content': text}]
|
||||||
sentiment = self.processing(text)
|
sentiment = self.processing(text)
|
||||||
return JSONResponse(content={"sentiment": sentiment}, status_code=status.HTTP_200_OK)
|
return JSONResponse(content={"sentiment": sentiment}, status_code=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|||||||
@ -22,8 +22,8 @@ class G2E(Blackbox):
|
|||||||
def processing(self, model_name, prompt, template, context: list) -> str:
|
def processing(self, model_name, prompt, template, context: list) -> str:
|
||||||
if context == None:
|
if context == None:
|
||||||
context = []
|
context = []
|
||||||
url = 'http://120.196.116.194:48890/v1'
|
#url = 'http://120.196.116.194:48890/v1'
|
||||||
#url = 'http://120.196.116.194:48892/v1'
|
url = 'http://120.196.116.194:48892/v1'
|
||||||
|
|
||||||
background_prompt = '''KOMBUKIKI是一款茶饮料,目标受众 年龄:20-35岁 性别:女性 地点:一线城市、二线城市 职业:精英中产、都市白领 收入水平:中高收入,有一定消费能力 兴趣和爱好:注重健康,有运动习惯
|
background_prompt = '''KOMBUKIKI是一款茶饮料,目标受众 年龄:20-35岁 性别:女性 地点:一线城市、二线城市 职业:精英中产、都市白领 收入水平:中高收入,有一定消费能力 兴趣和爱好:注重健康,有运动习惯
|
||||||
|
|
||||||
@ -65,7 +65,8 @@ class G2E(Blackbox):
|
|||||||
api_key='YOUR_API_KEY',
|
api_key='YOUR_API_KEY',
|
||||||
base_url=url
|
base_url=url
|
||||||
)
|
)
|
||||||
model_name = client.models.list().data[0].id
|
#model_name = client.models.list().data[0].id
|
||||||
|
model_name = client.models.list().data[1].id
|
||||||
print(model_name)
|
print(model_name)
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model=model_name,
|
model=model_name,
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
|
|
||||||
from dataclasses import dataclass
|
from injector import inject,singleton
|
||||||
from injector import Injector, inject
|
|
||||||
import yaml
|
import yaml
|
||||||
import sys
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
|
@singleton
|
||||||
class Configuration():
|
class Configuration():
|
||||||
|
|
||||||
@inject
|
@inject
|
||||||
@ -26,19 +27,18 @@ class Configuration():
|
|||||||
bbb:
|
bbb:
|
||||||
ccc: "hello world"
|
ccc: "hello world"
|
||||||
"""
|
"""
|
||||||
def get(self, path: str | list[str], cfg: dict = None):
|
def get(self, path: str | list[str], cfg: dict = None, default=None):
|
||||||
if isinstance(path, str):
|
if isinstance(path, str):
|
||||||
if cfg is None:
|
if cfg is None:
|
||||||
cfg = self.cfg
|
cfg = self.cfg
|
||||||
return self.get(path.split("."), cfg)
|
return self.get(path.split("."), cfg)
|
||||||
length = len(path)
|
length = len(path)
|
||||||
if length == 0 or not isinstance(cfg, dict):
|
if length == 0 or not isinstance(cfg, dict):
|
||||||
return None
|
return default
|
||||||
if length == 1:
|
if length == 1:
|
||||||
return cfg.get(path[0])
|
return cfg.get(path[0])
|
||||||
return self.get(path[1:], cfg.get(path[0]))
|
return self.get(path[1:], cfg.get(path[0]))
|
||||||
|
|
||||||
|
|
||||||
class TesouConf():
|
class TesouConf():
|
||||||
url: str
|
url: str
|
||||||
|
|
||||||
@ -53,3 +53,39 @@ class MeloConf():
|
|||||||
@inject
|
@inject
|
||||||
def __init__(self, config: Configuration) -> None:
|
def __init__(self, config: Configuration) -> None:
|
||||||
self.melotts = config.get("melotts.url")
|
self.melotts = config.get("melotts.url")
|
||||||
|
|
||||||
|
# 'CRITICAL': CRITICAL,
|
||||||
|
# 'FATAL': FATAL,
|
||||||
|
# 'ERROR': ERROR,
|
||||||
|
# 'WARN': WARNING,
|
||||||
|
# 'WARNING': WARNING,
|
||||||
|
# 'INFO': INFO,
|
||||||
|
# 'DEBUG': DEBUG,
|
||||||
|
# 'NOTSET': NOTSET,
|
||||||
|
DEFAULT_LEVEL="WARNING"
|
||||||
|
DEFAULT_TIME_FORMAT="%Y-%m-%d %H:%M:%S"
|
||||||
|
|
||||||
|
@singleton
|
||||||
|
class LogConf():
|
||||||
|
level: int
|
||||||
|
time_format = "%Y-%m-%d %H:%M:%S"
|
||||||
|
filename: str | None
|
||||||
|
@inject
|
||||||
|
def __init__(self,config: Configuration) -> None:
|
||||||
|
self.level = config.get("log.level")
|
||||||
|
c = config.get("log.level", default=DEFAULT_LEVEL).upper()
|
||||||
|
level=logging._nameToLevel.get(c)
|
||||||
|
if level is None:
|
||||||
|
self.level = logging.WARNING
|
||||||
|
else:
|
||||||
|
self.level = level
|
||||||
|
self.filename = config.get("log.filename")
|
||||||
|
self.time_format = config.get("log.time_format", default=DEFAULT_TIME_FORMAT)
|
||||||
|
|
||||||
|
@singleton
|
||||||
|
class EnvConf():
|
||||||
|
version: str
|
||||||
|
|
||||||
|
@inject
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.version = "0.0.1"
|
||||||
|
|||||||
13
src/log/handler.py
Normal file
13
src/log/handler.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
class LogHandler(logging.StreamHandler):
|
||||||
|
|
||||||
|
def __init__(self)-> None:
|
||||||
|
logging.Handler.__init__(self=self)
|
||||||
|
|
||||||
|
def emit(self, record) -> None:
|
||||||
|
print("emit", record)
|
||||||
|
|
||||||
|
def handle(self, record) -> None:
|
||||||
|
print("@ handle",record)
|
||||||
|
|
||||||
@ -16,7 +16,6 @@ from src.tts.vits.text.symbols import symbols
|
|||||||
from src.tts.vits.text import text_to_sequence
|
from src.tts.vits.text import text_to_sequence
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logging.getLogger().setLevel(logging.INFO)
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
dirbaspath = __file__.split("\\")[1:-1]
|
dirbaspath = __file__.split("\\")[1:-1]
|
||||||
|
|||||||
Reference in New Issue
Block a user