-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change dimensions of VectorField, move logic from view to controler. …
…Zbudowalismy go
- Loading branch information
1 parent
47a2263
commit 9da9801
Showing
9 changed files
with
40 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
from django.contrib import admin | ||
from .models import Bot | ||
|
||
admin.site.register(Bot) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
from http import HTTPStatus | ||
|
||
from bot.models import Bot | ||
import requests | ||
from pgvector.django import L2Distance | ||
|
||
from bot.schemas import BotIn, BotOut | ||
from chunks.models import Chunk | ||
|
||
|
||
def query_llm_controller(payload: BotIn) -> tuple[HTTPStatus, BotOut]: | ||
bot = Bot(**payload.dict()) | ||
return HTTPStatus.CREATED, bot | ||
# TODO: payload na embeding -> Vector -> Szukamy w bazie podobne -> dokument do payloada | ||
embeddings_body = { | ||
"input": payload.input | ||
} | ||
response = requests.post("http://192.168.0.3:9000/v1/embeddings/", json=embeddings_body) | ||
input_embedding = response.json()['data'][0]['embedding'] | ||
similar_chunk = Chunk.objects.order_by(L2Distance('embedding', input_embedding))[0] | ||
print(similar_chunk.text) | ||
llm_body = { | ||
"prompt": "\n\n### Instructions:\nOdpowiedz na pytanie "+ payload.input +"\n\nWiedząc że"+similar_chunk.text+"\n\n### Response:\n", | ||
"stop": [ | ||
"\n", | ||
"###" | ||
] | ||
} | ||
llm_response = requests.post("http://192.168.0.3:9000/v1/completions/", json=llm_body) | ||
llm_response = llm_response.json()['choices'][0]['text'] | ||
return HTTPStatus.OK, BotOut(output=str(llm_response)) |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,14 @@ | ||
import requests | ||
|
||
from http import HTTPStatus | ||
|
||
from django.http import HttpRequest | ||
from pgvector.django import L2Distance | ||
from ninja import Router | ||
|
||
from bot.schemas import BotIn, BotOut | ||
from bot.controllers import query_llm_controller | ||
from chunks.models import Chunk | ||
from ninja import Router | ||
from bot.schemas import BotIn, BotOut, BotError | ||
|
||
router = Router(tags=["Bot"]) | ||
|
||
|
||
@router.post("/bot/", response={HTTPStatus.CREATED: BotOut}) | ||
@router.post("/bot/", response={HTTPStatus.OK: BotOut}) | ||
def query_llm(request: HttpRequest, payload: BotIn): | ||
# TODO: payload na embeding -> Vector -> Szukamy w bazie podobne -> dokument do payloada | ||
response = requests.post("http://192.168.0.3:9000/v1/embeddings", data=payload.text) | ||
|
||
if not response.ok: | ||
return HTTPStatus.INTERNAL_SERVER_ERROR | ||
|
||
print(response.content) | ||
|
||
# Chunk.objects.order_by(L2Distance('embedding', response)) | ||
response = requests.post("0.0.0.0:9000/v1/completions", data=payload) | ||
return query_llm_controller(response) | ||
return query_llm_controller(payload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters