фикс имаге
This commit is contained in:
1 parent
53afac9852
commit
5be8fcce19
2 files changed
+14
-15
No files matched your search
+1
-2
@@ -43,7 +43,7 @@ DEFAULT_NOTIFY = "da"
|
||||
DEFAULT_MARKDOWN = "old"
|
||||
|
||||
# модель которая умеет принимать картинки очень важно
|
||||
IMAGE_MODEL = "ollama*gemma3:27b-cloud"
|
||||
IMAGE_MODEL = "ollama*gemma4:31b-cloud"
|
||||
|
||||
# я забыл если честно
|
||||
SHOW_ACC_MSG = True
|
||||
@@ -98,7 +98,6 @@ PROVIDERS = {
|
||||
# если да, то модель будет напрямую смотреть фото в messages
|
||||
MODELS = {
|
||||
"ollama": {
|
||||
"gemma3:27b-cloud": {"vision": False},
|
||||
"gemma4:31b-cloud": {"vision": True},
|
||||
},
|
||||
"krutoiapi": {
|
||||
|
||||
+13
-13
@@ -3,8 +3,6 @@ import re
|
||||
import shelve
|
||||
import time
|
||||
import ai
|
||||
import json
|
||||
import traceback
|
||||
|
||||
from configparser import DEFAULTSECT
|
||||
|
||||
@@ -71,7 +69,7 @@ async def generate(
|
||||
if images:
|
||||
if settings.get("vision"):
|
||||
for image in images:
|
||||
content += [{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image}"}}]
|
||||
content += [{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image['data']}"}}]
|
||||
else:
|
||||
for image in images:
|
||||
try:
|
||||
@@ -95,9 +93,13 @@ async def generate(
|
||||
user_contexts[user_id].append({"role": "user", "content": content})
|
||||
user_contexts[user_id] = user_contexts[user_id][-MAX_CONTEXT:]
|
||||
|
||||
messages = [{"role": "system", "content": system_prompt}] + user_contexts[
|
||||
user_id
|
||||
]
|
||||
context = []
|
||||
for i, m in enumerate(user_contexts[user_id]):
|
||||
if m.get("role") == "user" and i < len(user_contexts[user_id]) - 1:
|
||||
m = {**m, "content": [p for p in m["content"] if p.get("type") != "image_url"]}
|
||||
context.append(m)
|
||||
|
||||
messages = [{"role": "system", "content": system_prompt}] + context
|
||||
else:
|
||||
model = DEFAULT_MODEL.split("*", 2)
|
||||
settings = MODELS.get(model[0]).get(model[1])
|
||||
@@ -166,22 +168,20 @@ async def image2text(image) -> str:
|
||||
return ""
|
||||
model = IMAGE_MODEL.split("*", 1)
|
||||
api = PROVIDERS[model[0]]
|
||||
text = ""
|
||||
messages = [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{"type": "input_text", "text": IMAGE_PROMPT},
|
||||
{"type": "input_image", "image_url": f"data:image/jpeg;base64,{image}"},
|
||||
{"type": "text", "text": IMAGE_PROMPT},
|
||||
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image}"}},
|
||||
],
|
||||
}
|
||||
]
|
||||
async for response in ai.responses(
|
||||
url=api["url"], api_key=api["key"], model=model[1], input=messages, stream=False
|
||||
async for completion in ai.completions(
|
||||
url=api["url"], api_key=api["key"], model=model[1], messages=messages, stream=False
|
||||
):
|
||||
pass
|
||||
text = response.output_text
|
||||
return text
|
||||
return completion["choices"][0]["message"]["content"]
|
||||
|
||||
|
||||
async def openai_generate_text(
|
||||
|
||||
Reference in new issue
Block a user