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