mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
feat: text_and_image blockbox
This commit is contained in:
@ -10,6 +10,7 @@ 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
|
||||||
|
|
||||||
class BlackboxFactory:
|
class BlackboxFactory:
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ class BlackboxFactory:
|
|||||||
self.fastchat = Fastchat()
|
self.fastchat = Fastchat()
|
||||||
self.audio_chat = AudioChat(self.asr, self.tesou, self.tts)
|
self.audio_chat = AudioChat(self.asr, self.tesou, self.tts)
|
||||||
self.g2e = G2E()
|
self.g2e = G2E()
|
||||||
|
self.text_and_image = TextAndImage()
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
return self.processing(*args, **kwargs)
|
return self.processing(*args, **kwargs)
|
||||||
@ -52,4 +54,6 @@ class BlackboxFactory:
|
|||||||
return self.audio_chat
|
return self.audio_chat
|
||||||
if blackbox_name == "g2e":
|
if blackbox_name == "g2e":
|
||||||
return self.g2e
|
return self.g2e
|
||||||
|
if blackbox_name == 'text_and_image':
|
||||||
|
return self.text_and_image
|
||||||
raise ValueError("Invalid blockbox type")
|
raise ValueError("Invalid blockbox type")
|
||||||
@ -22,7 +22,7 @@ class G2E(Blackbox):
|
|||||||
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'
|
||||||
|
|
||||||
background_prompt = '''KOMBUKIKI是一款茶饮料,目标受众 年龄:20-35岁 性别:女性 地点:一线城市、二线城市 职业:精英中产、都市白领 收入水平:中高收入,有一定消费能力 兴趣和爱好:注重健康,有运动习惯
|
background_prompt = '''KOMBUKIKI是一款茶饮料,目标受众 年龄:20-35岁 性别:女性 地点:一线城市、二线城市 职业:精英中产、都市白领 收入水平:中高收入,有一定消费能力 兴趣和爱好:注重健康,有运动习惯
|
||||||
|
|
||||||
@ -47,8 +47,11 @@ class G2E(Blackbox):
|
|||||||
|
|
||||||
|
|
||||||
prompt_template = [
|
prompt_template = [
|
||||||
{"role": "system", "content": background_prompt + prompt1},
|
{"role": "system", "content": background_prompt + prompt1},
|
||||||
]
|
]
|
||||||
|
#prompt_template = [
|
||||||
|
# {"role": "system", "content": ''},
|
||||||
|
#]
|
||||||
|
|
||||||
|
|
||||||
messages = prompt_template + context + [
|
messages = prompt_template + context + [
|
||||||
@ -61,8 +64,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
|
||||||
|
print(model_name)
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model=model_name,
|
model=model_name,
|
||||||
messages=messages,
|
messages=messages,
|
||||||
|
|||||||
28
src/blackbox/text_and_image.py
Normal file
28
src/blackbox/text_and_image.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
from typing import Any, Coroutine
|
||||||
|
|
||||||
|
from fastapi import Request, Response, status
|
||||||
|
from fastapi.responses import JSONResponse
|
||||||
|
from .blackbox import Blackbox
|
||||||
|
|
||||||
|
|
||||||
|
class TextAndImage(Blackbox):
|
||||||
|
|
||||||
|
def __call__(self, *args, **kwargs):
|
||||||
|
return self.processing(*args, **kwargs)
|
||||||
|
|
||||||
|
def processing(self, text: str, image: bytes):
|
||||||
|
# TODO: implement the processing logic
|
||||||
|
return "text and image processing..."
|
||||||
|
|
||||||
|
def valid(self, *args, **kwargs) -> bool:
|
||||||
|
return True
|
||||||
|
|
||||||
|
async def fast_api_handler(self, request: Request) -> Response:
|
||||||
|
# If the request is a form data, you can use the following code
|
||||||
|
data = (await request.form()).get("image")
|
||||||
|
if data is None:
|
||||||
|
return JSONResponse(content={"error": "image is required"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||||
|
imageBytes = await data.read()
|
||||||
|
text = (await request.form()).get("text")
|
||||||
|
result = self.processing(text, imageBytes)
|
||||||
|
return JSONResponse(content={"result": result }, status_code=status.HTTP_200_OK)
|
||||||
Reference in New Issue
Block a user