Spaces:
Running
Running
Upload 76 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- bot/.DS_Store +0 -0
- bot/.views.py.swp +0 -0
- bot/__init__.py +0 -0
- bot/__pycache__/__init__.cpython-311.pyc +0 -0
- bot/__pycache__/admin.cpython-311.pyc +0 -0
- bot/__pycache__/apps.cpython-311.pyc +0 -0
- bot/__pycache__/forms.cpython-311.pyc +0 -0
- bot/__pycache__/models.cpython-311.pyc +0 -0
- bot/__pycache__/uchat.cpython-311.pyc +0 -0
- bot/__pycache__/urls.cpython-311.pyc +0 -0
- bot/__pycache__/views.cpython-311.pyc +0 -0
- bot/admin.py +6 -0
- bot/apps.py +6 -0
- bot/chroma_data/71205607-97fb-4292-8492-28d8f0cc5fef/data_level0.bin +3 -0
- bot/chroma_data/71205607-97fb-4292-8492-28d8f0cc5fef/header.bin +3 -0
- bot/chroma_data/71205607-97fb-4292-8492-28d8f0cc5fef/length.bin +3 -0
- bot/chroma_data/71205607-97fb-4292-8492-28d8f0cc5fef/link_lists.bin +3 -0
- bot/chroma_data/chroma.sqlite3 +0 -0
- bot/forms.py +62 -0
- bot/migrations/0001_initial.py +21 -0
- bot/migrations/0002_query.py +21 -0
- bot/migrations/0003_rename_text_query_query_language_lid_query_reply_and_more.py +35 -0
- bot/migrations/0004_param_alter_language_lid_alter_language_name.py +48 -0
- bot/migrations/__init__.py +0 -0
- bot/migrations/__pycache__/0001_initial.cpython-311.pyc +0 -0
- bot/migrations/__pycache__/0002_query.cpython-311.pyc +0 -0
- bot/migrations/__pycache__/0003_rename_text_query_query_language_lid_query_reply_and_more.cpython-311.pyc +0 -0
- bot/migrations/__pycache__/0004_param_alter_language_lid_alter_language_name.cpython-311.pyc +0 -0
- bot/migrations/__pycache__/__init__.cpython-311.pyc +0 -0
- bot/models.py +64 -0
- bot/static/css/styles.css +5 -0
- bot/test.wsgi +7 -0
- bot/tests.py +38 -0
- bot/tests/__init__.py +1 -0
- bot/tests/__pycache__/__init__.cpython-311.pyc +0 -0
- bot/tests/test_views.py +38 -0
- bot/uchat-old.py +322 -0
- bot/uchat.py +162 -0
- bot/urls.py +31 -0
- bot/views.py +624 -0
- templates/.DS_Store +0 -0
- templates/base_generic.html +74 -0
- templates/bot/language_detail.html +16 -0
- templates/bot/language_list.html +16 -0
- templates/index.html +41 -0
- templates/index_editor.html +76 -0
- templates/index_import.html +29 -0
- templates/index_params.html +107 -0
- templates/registration/logged_out.html +7 -0
- templates/registration/login.html +38 -0
bot/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
bot/.views.py.swp
ADDED
Binary file (53.2 kB). View file
|
|
bot/__init__.py
ADDED
File without changes
|
bot/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (150 Bytes). View file
|
|
bot/__pycache__/admin.cpython-311.pyc
ADDED
Binary file (355 Bytes). View file
|
|
bot/__pycache__/apps.cpython-311.pyc
ADDED
Binary file (515 Bytes). View file
|
|
bot/__pycache__/forms.cpython-311.pyc
ADDED
Binary file (4.38 kB). View file
|
|
bot/__pycache__/models.cpython-311.pyc
ADDED
Binary file (5.52 kB). View file
|
|
bot/__pycache__/uchat.cpython-311.pyc
ADDED
Binary file (10.3 kB). View file
|
|
bot/__pycache__/urls.cpython-311.pyc
ADDED
Binary file (1.23 kB). View file
|
|
bot/__pycache__/views.cpython-311.pyc
ADDED
Binary file (34.5 kB). View file
|
|
bot/admin.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.contrib import admin
|
2 |
+
from .models import Language
|
3 |
+
|
4 |
+
admin.site.register(Language)
|
5 |
+
|
6 |
+
# Register your models here.
|
bot/apps.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.apps import AppConfig
|
2 |
+
|
3 |
+
|
4 |
+
class BotConfig(AppConfig):
|
5 |
+
default_auto_field = 'django.db.models.BigAutoField'
|
6 |
+
name = 'bot'
|
bot/chroma_data/71205607-97fb-4292-8492-28d8f0cc5fef/data_level0.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6a0f748340f882ae5b8ef64a529d2782a281c1fa7bb7be42203e031a07c2a2dd
|
3 |
+
size 1676000
|
bot/chroma_data/71205607-97fb-4292-8492-28d8f0cc5fef/header.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e87a1dc8bcae6f2c4bea6d5dd5005454d4dace8637dae29bff3c037ea771411e
|
3 |
+
size 100
|
bot/chroma_data/71205607-97fb-4292-8492-28d8f0cc5fef/length.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9d5aebd05d5bf364ed999da7c13f7ef2101df1dc00f19fc87758d2d7cc067582
|
3 |
+
size 4000
|
bot/chroma_data/71205607-97fb-4292-8492-28d8f0cc5fef/link_lists.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
3 |
+
size 0
|
bot/chroma_data/chroma.sqlite3
ADDED
Binary file (147 kB). View file
|
|
bot/forms.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.core.exceptions import ValidationError
|
2 |
+
#from django.utils.translation import gettext_lazy as _
|
3 |
+
|
4 |
+
from django import forms
|
5 |
+
|
6 |
+
class RenewBotForm(forms.Form):
|
7 |
+
query = forms.CharField(
|
8 |
+
help_text="Unesite upit: ")
|
9 |
+
jezik = forms.CharField(
|
10 |
+
help_text="Odaberite jezik")
|
11 |
+
# def clean_query(self):
|
12 |
+
# data = self.cleaned_data['query']
|
13 |
+
# data = self.cleaned_data['jezik']
|
14 |
+
# return data
|
15 |
+
|
16 |
+
class EditorForm(forms.Form):
|
17 |
+
id = forms.CharField(help_text="id")
|
18 |
+
state = forms.CharField(help_text="Početno stanje")
|
19 |
+
next = forms.CharField(help_text="Završno stanje")
|
20 |
+
page = forms.IntegerField(help_text="Stranica")
|
21 |
+
used = forms.CharField(help_text="Upotrebljen (Bool)")
|
22 |
+
docu = forms.CharField(help_text="Dokument konteksta")
|
23 |
+
source = forms.CharField(help_text="URL dokumenta")
|
24 |
+
jezik = forms.CharField(help_text="Odaberite jezik")
|
25 |
+
# def clean_query(self):
|
26 |
+
# data = self.cleaned_data['source']
|
27 |
+
# return data
|
28 |
+
|
29 |
+
class EditorListForm(forms.Form):
|
30 |
+
f_id = forms.IntegerField(help_text="id filter")
|
31 |
+
f_jezik = forms.CharField(help_text="jezik filter")
|
32 |
+
f_state = forms.CharField(help_text="state filter")
|
33 |
+
f_next = forms.CharField(help_text="next filter")
|
34 |
+
f_page = forms.IntegerField(help_text="page filter")
|
35 |
+
f_docu = forms.CharField(help_text="document filter")
|
36 |
+
|
37 |
+
class ParamForm(forms.Form):
|
38 |
+
system = forms.CharField(help_text="Enter parameter value")
|
39 |
+
ctxpre = forms.CharField(help_text="Enter parameter value")
|
40 |
+
msg_content = forms.CharField(help_text="Enter parameter value")
|
41 |
+
min_len = forms.IntegerField(help_text="Enter parameter value")
|
42 |
+
CHUNK_SIZE = forms.IntegerField(help_text="Enter parameter value")
|
43 |
+
CHUNK_OVERLAP = forms.IntegerField(help_text="Enter parameter value")
|
44 |
+
max_results = forms.IntegerField(help_text="Enter parameter value")
|
45 |
+
EMBED_MODEL = forms.CharField(help_text="Enter parameter value")
|
46 |
+
model_id = forms.CharField(help_text="Enter parameter value")
|
47 |
+
max_results = forms.IntegerField(help_text="Enter parameter value")
|
48 |
+
max_conv = forms.IntegerField(help_text="Enter parameter value")
|
49 |
+
min_len = forms.IntegerField(help_text="Enter parameter value")
|
50 |
+
min_distance = forms.FloatField(help_text="Enter parameter value")
|
51 |
+
max_distance = forms.FloatField(help_text="Enter parameter value")
|
52 |
+
temperature = forms.FloatField(help_text="Enter parameter value")
|
53 |
+
max_tokens = forms.IntegerField(help_text="Enter parameter value")
|
54 |
+
top_p = forms.FloatField(help_text="Enter parameter value")
|
55 |
+
frequency_penalty = forms.FloatField(help_text="Enter parameter value")
|
56 |
+
presence_penalty = forms.FloatField(help_text="Enter parameter value")
|
57 |
+
DEBUG = forms.CharField(help_text="Enter parameter value (Bool)")
|
58 |
+
jezik = forms.CharField(help_text="Uneti jezik")
|
59 |
+
|
60 |
+
class ImportForm(forms.Form):
|
61 |
+
path = forms.CharField(help_text="Unesite putanju do PDF dokumenta")
|
62 |
+
jezik = forms.CharField(help_text="Unesite jezik")
|
bot/migrations/0001_initial.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Generated by Django 5.0.3 on 2024-04-04 02:48
|
2 |
+
|
3 |
+
from django.db import migrations, models
|
4 |
+
|
5 |
+
|
6 |
+
class Migration(migrations.Migration):
|
7 |
+
|
8 |
+
initial = True
|
9 |
+
|
10 |
+
dependencies = [
|
11 |
+
]
|
12 |
+
|
13 |
+
operations = [
|
14 |
+
migrations.CreateModel(
|
15 |
+
name='Language',
|
16 |
+
fields=[
|
17 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
18 |
+
('name', models.CharField(help_text='Enter language (e.g. English, French, Japanese etc.)', max_length=200, unique=True)),
|
19 |
+
],
|
20 |
+
),
|
21 |
+
]
|
bot/migrations/0002_query.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Generated by Django 5.0.3 on 2024-04-06 04:37
|
2 |
+
|
3 |
+
from django.db import migrations, models
|
4 |
+
|
5 |
+
|
6 |
+
class Migration(migrations.Migration):
|
7 |
+
|
8 |
+
dependencies = [
|
9 |
+
('bot', '0001_initial'),
|
10 |
+
]
|
11 |
+
|
12 |
+
operations = [
|
13 |
+
migrations.CreateModel(
|
14 |
+
name='Query',
|
15 |
+
fields=[
|
16 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
17 |
+
('text', models.TextField(help_text='Unesite upit', max_length=1000)),
|
18 |
+
('jezik', models.CharField(help_text='Odaberite jezik!', max_length=16)),
|
19 |
+
],
|
20 |
+
),
|
21 |
+
]
|
bot/migrations/0003_rename_text_query_query_language_lid_query_reply_and_more.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Generated by Django 5.0.3 on 2024-04-10 18:33
|
2 |
+
|
3 |
+
from django.db import migrations, models
|
4 |
+
|
5 |
+
|
6 |
+
class Migration(migrations.Migration):
|
7 |
+
|
8 |
+
dependencies = [
|
9 |
+
('bot', '0002_query'),
|
10 |
+
]
|
11 |
+
|
12 |
+
operations = [
|
13 |
+
migrations.RenameField(
|
14 |
+
model_name='query',
|
15 |
+
old_name='text',
|
16 |
+
new_name='query',
|
17 |
+
),
|
18 |
+
migrations.AddField(
|
19 |
+
model_name='language',
|
20 |
+
name='lid',
|
21 |
+
field=models.CharField(default='sr', help_text='Unesite kratak naziv jezika', max_length=2),
|
22 |
+
preserve_default=False,
|
23 |
+
),
|
24 |
+
migrations.AddField(
|
25 |
+
model_name='query',
|
26 |
+
name='reply',
|
27 |
+
field=models.TextField(default='default', help_text='Unesite odgovor', max_length=1000),
|
28 |
+
preserve_default=False,
|
29 |
+
),
|
30 |
+
migrations.AlterField(
|
31 |
+
model_name='language',
|
32 |
+
name='name',
|
33 |
+
field=models.CharField(help_text='Unesite jezik', max_length=16, unique=True),
|
34 |
+
),
|
35 |
+
]
|
bot/migrations/0004_param_alter_language_lid_alter_language_name.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Generated by Django 5.0.3 on 2024-04-22 03:29
|
2 |
+
|
3 |
+
from django.db import migrations, models
|
4 |
+
|
5 |
+
|
6 |
+
class Migration(migrations.Migration):
|
7 |
+
|
8 |
+
dependencies = [
|
9 |
+
('bot', '0003_rename_text_query_query_language_lid_query_reply_and_more'),
|
10 |
+
]
|
11 |
+
|
12 |
+
operations = [
|
13 |
+
migrations.CreateModel(
|
14 |
+
name='Param',
|
15 |
+
fields=[
|
16 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
17 |
+
('system', models.TextField(default='System prpmpt', help_text='Enter parameter value', max_length=2048)),
|
18 |
+
('ctxpre', models.CharField(blank=True, help_text='Enter parameter value', max_length=80)),
|
19 |
+
('msg_content', models.CharField(blank=True, help_text='Enter parameter value', max_length=80)),
|
20 |
+
('min_len', models.IntegerField(default=40, help_text='Enter parameter value')),
|
21 |
+
('CHUNK_SIZE', models.IntegerField(default=800, help_text='Enter parameter value')),
|
22 |
+
('CHUNK_OVERLAP', models.IntegerField(default=50, help_text='Enter parameter value')),
|
23 |
+
('max_results', models.IntegerField(default=3, help_text='Enter parameter value')),
|
24 |
+
('EMBED_MODEL', models.CharField(default='embeddings model', help_text='Enter parameter value', max_length=256)),
|
25 |
+
('model_id', models.CharField(default='LLM model', help_text='Enter parameter value', max_length=256)),
|
26 |
+
('max_conv', models.IntegerField(default=3, help_text='Enter parameter value')),
|
27 |
+
('min_distance', models.FloatField(default=0.35, help_text='Enter parameter value')),
|
28 |
+
('max_distance', models.FloatField(default=0.6, help_text='Enter parameter value')),
|
29 |
+
('temperature', models.FloatField(default=0.55, help_text='Enter parameter value')),
|
30 |
+
('max_tokens', models.IntegerField(default=3072, help_text='Enter parameter value')),
|
31 |
+
('top_p', models.FloatField(default=0.8, help_text='Enter parameter value')),
|
32 |
+
('frequency_penalty', models.FloatField(default=0.0, help_text='Enter parameter value')),
|
33 |
+
('presence_penalty', models.FloatField(default=0.0, help_text='Enter parameter value')),
|
34 |
+
('DEBUG', models.BooleanField(default=True, help_text='Enter parameter value')),
|
35 |
+
('jezik', models.CharField(default='srpski', help_text='Uneti jezik', max_length=16)),
|
36 |
+
],
|
37 |
+
),
|
38 |
+
migrations.AlterField(
|
39 |
+
model_name='language',
|
40 |
+
name='lid',
|
41 |
+
field=models.CharField(default='sr', help_text='Unesite kratak naziv jezika', max_length=2),
|
42 |
+
),
|
43 |
+
migrations.AlterField(
|
44 |
+
model_name='language',
|
45 |
+
name='name',
|
46 |
+
field=models.CharField(default='srpski', help_text='Unesite jezik', max_length=16, unique=True),
|
47 |
+
),
|
48 |
+
]
|
bot/migrations/__init__.py
ADDED
File without changes
|
bot/migrations/__pycache__/0001_initial.cpython-311.pyc
ADDED
Binary file (1.02 kB). View file
|
|
bot/migrations/__pycache__/0002_query.cpython-311.pyc
ADDED
Binary file (1.06 kB). View file
|
|
bot/migrations/__pycache__/0003_rename_text_query_query_language_lid_query_reply_and_more.cpython-311.pyc
ADDED
Binary file (1.41 kB). View file
|
|
bot/migrations/__pycache__/0004_param_alter_language_lid_alter_language_name.cpython-311.pyc
ADDED
Binary file (3.13 kB). View file
|
|
bot/migrations/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (161 Bytes). View file
|
|
bot/models.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.db import models
|
2 |
+
from django.urls import reverse
|
3 |
+
from django.forms import ModelForm
|
4 |
+
|
5 |
+
class Query(models.Model):
|
6 |
+
query = models.TextField(
|
7 |
+
max_length=1000, help_text="Unesite upit")
|
8 |
+
reply = models.TextField(
|
9 |
+
max_length=1000, help_text="Unesite odgovor")
|
10 |
+
jezik = models.CharField(
|
11 |
+
max_length=16, help_text="Odaberite jezik!")
|
12 |
+
def get_absolute_url(self):
|
13 |
+
return reverse('query', args=[str(self.id)])
|
14 |
+
def __str__(self):
|
15 |
+
return self.text
|
16 |
+
|
17 |
+
#class QueryForm(ModelForm):
|
18 |
+
# class Meta:
|
19 |
+
# model = Query
|
20 |
+
# fields = ['query', 'reply', 'jezik']
|
21 |
+
|
22 |
+
class Language(models.Model):
|
23 |
+
name = models.CharField(max_length=16,
|
24 |
+
unique=True,
|
25 |
+
default="srpski",
|
26 |
+
help_text="Unesite jezik")
|
27 |
+
lid = models.CharField(max_length=2, unique=False, default="sr", help_text="Unesite kratak naziv jezika")
|
28 |
+
def get_absolute_url(self):
|
29 |
+
"""Returns the url to access a particular language instance."""
|
30 |
+
return reverse('bot-detail', args=[str(self.id)])
|
31 |
+
def __str__(self):
|
32 |
+
"""String for representing the Model object (in Admin site etc.)"""
|
33 |
+
return self.name
|
34 |
+
|
35 |
+
class LanguageForm(ModelForm):
|
36 |
+
class Meta:
|
37 |
+
model = Language
|
38 |
+
fields = ['name', 'lid']
|
39 |
+
|
40 |
+
class Param(models.Model):
|
41 |
+
system = models.TextField(max_length=2048, unique=False, blank=False, default="System prpmpt", help_text="Enter parameter value")
|
42 |
+
ctxpre = models.CharField(max_length=80, unique=False, blank=True, help_text="Enter parameter value")
|
43 |
+
msg_content = models.CharField(unique=False, blank=True, max_length=80, help_text="Enter parameter value")
|
44 |
+
min_len = models.IntegerField(unique=False, blank=False, default=40, help_text="Enter parameter value")
|
45 |
+
CHUNK_SIZE = models.IntegerField(unique=False, blank=False, default=800, help_text="Enter parameter value")
|
46 |
+
CHUNK_OVERLAP = models.IntegerField(unique=False, blank=False, default=50, help_text="Enter parameter value")
|
47 |
+
max_results = models.IntegerField(unique=False, blank=False, default=3, help_text="Enter parameter value")
|
48 |
+
EMBED_MODEL = models.CharField(max_length=256, default="embeddings model", help_text="Enter parameter value")
|
49 |
+
model_id = models.CharField(max_length=256, unique=False, default="LLM model", blank=False, help_text="Enter parameter value")
|
50 |
+
max_conv = models.IntegerField(unique=False, blank=False, default=3, help_text="Enter parameter value")
|
51 |
+
min_distance = models.FloatField(unique=False, blank=False, default=0.35, help_text="Enter parameter value")
|
52 |
+
max_distance = models.FloatField(unique=False, blank=False, default=0.6, help_text="Enter parameter value")
|
53 |
+
temperature = models.FloatField(unique=False, blank=False, default=0.55, help_text="Enter parameter value")
|
54 |
+
max_tokens = models.IntegerField(unique=False, blank=False, default=3072, help_text="Enter parameter value")
|
55 |
+
top_p = models.FloatField(unique=False, blank=False, default=0.8, help_text="Enter parameter value")
|
56 |
+
frequency_penalty = models.FloatField(unique=False, default=0.0, blank=False, help_text="Enter parameter value")
|
57 |
+
presence_penalty = models.FloatField(unique=False, default=0.0, blank=False, help_text="Enter parameter value")
|
58 |
+
DEBUG = models.BooleanField(unique=False, blank=False, default=True, help_text="Enter parameter value")
|
59 |
+
jezik = models.CharField(max_length=16, unique=False, blank=False, default="srpski", help_text="Uneti jezik")
|
60 |
+
|
61 |
+
class ParamModelForm(ModelForm):
|
62 |
+
class Meta:
|
63 |
+
model = Param
|
64 |
+
fields = [ 'system', 'ctxpre', 'msg_content', 'min_len', 'CHUNK_SIZE', 'CHUNK_OVERLAP', 'max_results', 'EMBED_MODEL', 'model_id', 'max_conv', 'min_distance', 'max_distance', 'temperature', 'max_tokens', 'top_p', 'frequency_penalty', 'presence_penalty', 'DEBUG', 'jezik']
|
bot/static/css/styles.css
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.sidebar-nav {
|
2 |
+
margin-top: 20px;
|
3 |
+
padding: 0;
|
4 |
+
list-style: none;
|
5 |
+
}
|
bot/test.wsgi
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def application(environ, start_response):
|
2 |
+
status = '200 OK'
|
3 |
+
output = b'Hello World!'
|
4 |
+
response_headers = [('Content-type', 'text/plain'),
|
5 |
+
('Content-Length', str(len(output)))]
|
6 |
+
start_response(status, response_headers)
|
7 |
+
return [output]
|
bot/tests.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.test import TestCase
|
2 |
+
|
3 |
+
# Create your tests here.
|
4 |
+
|
5 |
+
|
6 |
+
from catalog.models import Language
|
7 |
+
from django.urls import reverse
|
8 |
+
|
9 |
+
|
10 |
+
class LanguageViewTest(TestCase):
|
11 |
+
|
12 |
+
@classmethod
|
13 |
+
def setUpTestData(cls):
|
14 |
+
langs = [ 'Hrvatski', 'Slovenački', 'Srpski', 'Bosanski', 'Makedonski', 'Bugarski']
|
15 |
+
for lang in langs:
|
16 |
+
l = Language.objects.create(name=lang) ; l.save()
|
17 |
+
|
18 |
+
import datetime
|
19 |
+
from django.utils import timezone
|
20 |
+
|
21 |
+
from bot.models import Language
|
22 |
+
|
23 |
+
# Get user model from settings
|
24 |
+
from django.contrib.auth import get_user_model
|
25 |
+
User = get_user_model()
|
26 |
+
|
27 |
+
class UserViewTest(TestCase):
|
28 |
+
|
29 |
+
def setUp(self):
|
30 |
+
# Create two users
|
31 |
+
test_user1 = User.objects.create_user(
|
32 |
+
username='testuser1', password='testuser1')
|
33 |
+
test_user2 = User.objects.create_user(
|
34 |
+
username='testuser2', password='testuser2')
|
35 |
+
|
36 |
+
test_user1.save()
|
37 |
+
test_user2.save()
|
38 |
+
|
bot/tests/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
|
bot/tests/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (156 Bytes). View file
|
|
bot/tests/test_views.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.test import TestCase
|
2 |
+
|
3 |
+
# Create your tests here.
|
4 |
+
|
5 |
+
|
6 |
+
from catalog.models import Language
|
7 |
+
from django.urls import reverse
|
8 |
+
|
9 |
+
|
10 |
+
class LanguageViewTest(TestCase):
|
11 |
+
|
12 |
+
@classmethod
|
13 |
+
def setUpTestData(cls):
|
14 |
+
langs = [ 'Hrvatski', 'Slovenački', 'Srpski', 'Bosanski', 'Makedonski', 'Bugarski']
|
15 |
+
for lang in langs:
|
16 |
+
l = Language.objects.create(name=lang) ; l.save()
|
17 |
+
|
18 |
+
import datetime
|
19 |
+
from django.utils import timezone
|
20 |
+
|
21 |
+
from bot.models import Language
|
22 |
+
|
23 |
+
# Get user model from settings
|
24 |
+
from django.contrib.auth import get_user_model
|
25 |
+
User = get_user_model()
|
26 |
+
|
27 |
+
class UserViewTest(TestCase):
|
28 |
+
|
29 |
+
def setUp(self):
|
30 |
+
# Create two users
|
31 |
+
test_user1 = User.objects.create_user(
|
32 |
+
username='testuser1', password='testuser1')
|
33 |
+
test_user2 = User.objects.create_user(
|
34 |
+
username='testuser2', password='testuser2')
|
35 |
+
|
36 |
+
test_user1.save()
|
37 |
+
test_user2.save()
|
38 |
+
|
bot/uchat-old.py
ADDED
@@ -0,0 +1,322 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import chromadb
|
2 |
+
from chromadb.utils import embedding_functions
|
3 |
+
import os
|
4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
+
import torch
|
6 |
+
from openai import OpenAI
|
7 |
+
from langchain_community.document_loaders import PyPDFLoader
|
8 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
9 |
+
from itertools import islice, zip_longest
|
10 |
+
import re
|
11 |
+
|
12 |
+
#model_id = "mistralai/Mistral-7B-Instruct-v0.2"
|
13 |
+
#tokenizer = AutoTokenizer.from_pretrained(model_id)
|
14 |
+
model_id = "Yugo60-GPT-GGUF.Q4_K_M.gguf"
|
15 |
+
|
16 |
+
#inputs = tokenizer(text, return_tensors="pt").to(0)
|
17 |
+
|
18 |
+
#outputs = model.generate(**inputs, max_new_tokens=20)
|
19 |
+
#print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
20 |
+
|
21 |
+
if not torch.backends.mps.is_available():
|
22 |
+
if not torch.backends.mps.is_built():
|
23 |
+
print("MPS not available because the current PyTorch install was not "
|
24 |
+
"built with MPS enabled.")
|
25 |
+
else:
|
26 |
+
print("MPS not available because the current MacOS version is not 12.3+ "
|
27 |
+
"and/or you do not have an MPS-enabled device on this machine.")
|
28 |
+
else:
|
29 |
+
torch.set_default_device("mps")
|
30 |
+
|
31 |
+
model = ""
|
32 |
+
CHROMA_DATA_PATH = "chroma_data/"
|
33 |
+
EMBED_MODEL = "all-MiniLM-L6-v2"
|
34 |
+
# NousResearch/Hermes-2-Pro-Mistral-7B
|
35 |
+
# distilbert-base-multilingual-case
|
36 |
+
# paraphrase-multilingual-MiniLM-L12-v2d
|
37 |
+
COLLECTION_NAME = "chroma_data"
|
38 |
+
PDF_PATH = "./PDF/uputstvo_uz_eon_smart_box-1.pdf"
|
39 |
+
PDF_PATH2 = "./PDF/uputstvo_uz_eon_smart_aplikaciju-1.pdf"
|
40 |
+
CHUNK_SIZE = 800
|
41 |
+
CHUNK_OVERLAP = 50
|
42 |
+
max_results = 3
|
43 |
+
min_len = 40
|
44 |
+
|
45 |
+
def load_and_split_document(pdf_path):
|
46 |
+
loader = PyPDFLoader(pdf_path)
|
47 |
+
print('Loaded: ' + pdf_path)
|
48 |
+
return loader.load_and_split()
|
49 |
+
|
50 |
+
def split_text_into_chunks(pages, chunk_size, chunk_overlap):
|
51 |
+
n = -1
|
52 |
+
for page in range(len(pages)): pages[page].page_content = re.sub(r'\s+'," ", pages[page].page_content.replace(". .","").replace(r'\n','.')).replace('..','')
|
53 |
+
for p in range(len(pages)):
|
54 |
+
if len(pages[p].page_content)<min_len:
|
55 |
+
if n<0: n = p
|
56 |
+
else:
|
57 |
+
if n>=0:
|
58 |
+
pages[n]=pages[p]; n += 1
|
59 |
+
if n>0: pages = pages[:n-1]
|
60 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap)
|
61 |
+
return text_splitter.split_documents(pages)
|
62 |
+
|
63 |
+
def batched(iterable, n):
|
64 |
+
it = iter(iterable)
|
65 |
+
while True:
|
66 |
+
batch = list(islice(it, n))
|
67 |
+
if not batch:
|
68 |
+
return
|
69 |
+
yield batch
|
70 |
+
|
71 |
+
client = chromadb.PersistentClient(path=CHROMA_DATA_PATH)
|
72 |
+
client.allow_reset = True
|
73 |
+
client.delete_collection(COLLECTION_NAME)
|
74 |
+
|
75 |
+
oc = OpenAI(base_url="http://localhost:4891/v1", api_key="not-needed")
|
76 |
+
|
77 |
+
docs = [
|
78 |
+
"s0", [
|
79 |
+
[
|
80 |
+
"",
|
81 |
+
"Navedite, da li je problem sa EON uređajem, upravljačem ili WiFi mrežom?",
|
82 |
+
"Problem sa TV odabirom sadržaja, prijemom signala ili dostupnošću usluga?",
|
83 |
+
"Problem sa naplatom usluga?",
|
84 |
+
],
|
85 |
+
[ "s00", "Ako korisnik ima problema sa prijemom kablovskog signala ili slikom, proveriti EON SMART BOX uređaj", "Ako korisnik ima problem sa EON SMART BOX uređajem ili aplikacijom, treba proveriti EON podešavanja", "Ako je korisniku poptpuno crn ekran, proveriti resetovanje EON SMART BOX uređaja ili aplikacije" ],
|
86 |
+
[ "s01", "Ako nee radi internet korisniku, treba proveriti kablovski prijem", "Ako ne radi WiFi korisniku, onda proveriti priključen WiFI ruter" ],
|
87 |
+
[ "s02", "Ako korisnik ima problema sa izborom kanala, proveriti podešavanja ili pretplatu", "Ako ne radi daljinski upravljač, proveriti EON SMART BOX uređaj" ],
|
88 |
+
[ "s03", "Ako korisnik ima problema s plaćanjem pretplate, neka ga proveri ili izmiri na web stranici ili najbližoj filijali.", "Ako korisnik dobije poruku o neizmirenim obavezama na ekranu, neka proveri stanje pretplate na web strasnici ili u najbližoj filijali.", "Ako korisnik želi proveru stanja bez web stranice ili filijale, neka se obrati Call centru", "Ako korisnik želi naplatu obaveza ili promenu paketa usluga, neka se obrati Call centru." ],
|
89 |
+
],
|
90 |
+
"s00", [
|
91 |
+
[
|
92 |
+
"Ako korisnik nije resetovao EON SMART BOX uređaj ili aplikaciju, neka pokuša da ga restartuje, kao i TV uređaj.",
|
93 |
+
"Ako problem korisniku nije rešen resetovanjem, onda ga uputiti na Call centar.",
|
94 |
+
],
|
95 |
+
[ "s000", "Ako je resetovanje bilo uspešno, ali korisnik i dalje ima problem, neka se obrati call centru.", "Ako korisnik ne zna kako da resetuje uređaj, neka ga isključi iz struje na nekoliko sekundi, i ponovo uključi." ],
|
96 |
+
[ "s99", "Ako je korisniku nejasan odgovor, neka se obrati Call centru."],
|
97 |
+
],
|
98 |
+
"s01", [
|
99 |
+
[
|
100 |
+
"Ako korisnik ima problema sa internetom, neka pokuša da restartuje WiFi ruter.",
|
101 |
+
"Ako se korisniku problem nastavlja i nakon resetovanja, neka pokuša sa resetovanje EON SMART BOX i WiFI uređaja.",
|
102 |
+
],
|
103 |
+
[ "s010", "Ako korisnik ima problem sa prijemom kablovskog i internet signala, a resetovanje nije pomoglo, neka se obrati Call centru.", "Ako korisnik ima kablovski prijem, ali mu internet ne radi, neka proveri da li radim ping 8.8.8.8"],
|
104 |
+
[ "s00", "Ako korisnik ima kablovski prijem, ali internet ne radi, neka resetuje WiFI rutter", "Ako korisnuku rade TV kanali ali ne i internet, neka resetuje WiFI ruter", "Ako korisnik može gledati TV ali mu internet ne radi, neka resetuje WiFi ruter."],
|
105 |
+
[ "s99", "Ako je korisniku nejasan odgovor, neka se obrati Call centru." ],
|
106 |
+
],
|
107 |
+
"s02", [
|
108 |
+
[
|
109 |
+
"Ako korisniku nisu dostpni samo pojedini kanali, neka proveri stanje pretplate.",
|
110 |
+
"Ako korisniku nije dostupna nijedna funkcija na daljinskom upravljaču, neka pokuša da promeni baterije ili daljinski upravljać.",
|
111 |
+
],
|
112 |
+
[ "s03", "Ako korisnik želi da promeni paket usluga, neka se obrati Call centru.", "Ako korisnik želi da proveri stanje pretplate na svom računu, neka proveri stanje na web stranici ili preko Call centra." ],
|
113 |
+
[ "s99", "Ako je korisniku nejasan odgovor, neka se obrati Call centru." ],
|
114 |
+
],
|
115 |
+
"s03", [
|
116 |
+
[
|
117 |
+
"Ako niste izmirili Vaše redovne obaveze, možete to učiniti online, ili putem najbližeg predstavništva.",
|
118 |
+
],
|
119 |
+
[ "s99", "Ako je korisniku nejasan odgovor, neka se obrati Call centru." ],
|
120 |
+
],
|
121 |
+
"s09", [
|
122 |
+
[
|
123 |
+
"Kontaktirajte Call centar za korisničku podrškua na 0800123123123",
|
124 |
+
],
|
125 |
+
[ "s0", "Ako je korisniku nejasan odgovor, neka se obrati Call centru."]
|
126 |
+
],
|
127 |
+
"s000", [
|
128 |
+
[
|
129 |
+
"Ako korisnik ne zna kako da resetuje uređaj ili aplikaciju, neka isključi uređaj iz struje, i nakon nekoliko sekundi ponovo ga uključi.",
|
130 |
+
],
|
131 |
+
[ "s99", "Ako korisniku i dalje ima problem, neka se obrati Call centru.", "Ako korisnik ima novi problem, zahtevaj pojašnjenje." ],
|
132 |
+
],
|
133 |
+
"s010", [
|
134 |
+
[
|
135 |
+
"Ako korisniku radi ping a ima problem sa internetom, neka pokuša da postavi u svom browser-u ili mrežnim podešavanjima korisničkog uređaja 8.8.8.8 kao DNS",
|
136 |
+
],
|
137 |
+
[ "s99", "Ako se korisnik žali da mu nešto ne radi i dalje, uputite ga na Call centar", "Ako korisniku ne pomaže odgovor, neka se obrati Call centru." ],
|
138 |
+
],
|
139 |
+
"s99", [
|
140 |
+
[
|
141 |
+
"Odgovorite korisniku na sledeći način isključivo: Žao mi je, ali ne mogu Vam pomoći. Kontaktirajte Call centar na 08001231231223"
|
142 |
+
],
|
143 |
+
[ "s0", "Ako je korisniku nejasan odgovor, neka se obrati Call centru." ],
|
144 |
+
]
|
145 |
+
]
|
146 |
+
|
147 |
+
if not os.path.exists(CHROMA_DATA_PATH):
|
148 |
+
os.makedirs(CHROMA_DATA_PATH)
|
149 |
+
|
150 |
+
chroma_client = chromadb.PersistentClient(CHROMA_DATA_PATH)
|
151 |
+
|
152 |
+
embedding_func = embedding_functions.SentenceTransformerEmbeddingFunction(
|
153 |
+
model_name=EMBED_MODEL
|
154 |
+
)
|
155 |
+
|
156 |
+
collection = chroma_client.get_or_create_collection(
|
157 |
+
name="chroma_data",
|
158 |
+
embedding_function=embedding_func,
|
159 |
+
metadata={"hnsw:space": "cosine"},
|
160 |
+
)
|
161 |
+
|
162 |
+
#async function main() {
|
163 |
+
last = 0
|
164 |
+
state = -2
|
165 |
+
used =[]
|
166 |
+
for g in docs[0::2]:
|
167 |
+
state += 2
|
168 |
+
documents=docs[state+1][0]
|
169 |
+
collection.add(
|
170 |
+
documents=documents,
|
171 |
+
ids=[f"id{last+i}" for i in range(len(documents))],
|
172 |
+
metadatas=[{"state": g, "next": g, "used": False, "source": 'None', "page": -1 } for i in range(len(documents)) ]
|
173 |
+
)
|
174 |
+
for i in range(len(documents)): used += [0]
|
175 |
+
last += len(documents)
|
176 |
+
if (len(docs[state+1])>1):
|
177 |
+
for n in docs[state+1][1:]:
|
178 |
+
collection.add(
|
179 |
+
documents=n[1:],
|
180 |
+
ids=[f"id{last+i-1}" for i in range(1,len(n))],
|
181 |
+
metadatas=[{"state": g, "next": n[0], "used": False, "source": 'None', "page": -1 } for i in range(1,len(n)) ]
|
182 |
+
)
|
183 |
+
for i in range(1,len(n)): used += [0]
|
184 |
+
last += len(n)-1
|
185 |
+
|
186 |
+
state += 2
|
187 |
+
docus = load_and_split_document(PDF_PATH) + load_and_split_document(PDF_PATH2)
|
188 |
+
|
189 |
+
pages = split_text_into_chunks(docus, CHUNK_SIZE, CHUNK_OVERLAP)
|
190 |
+
document_indices = list(range(len(pages)))
|
191 |
+
for batch in batched(document_indices, 166):
|
192 |
+
collection.add(
|
193 |
+
ids=[f"id{last+batch[i]}" for i in range(len(batch))],
|
194 |
+
documents=[pages[i].page_content for i in batch],
|
195 |
+
metadatas=[dict(dict(dict(pages[i].metadata, used=False), next='None'), state='None') for i in batch],
|
196 |
+
)
|
197 |
+
last += len(batch)
|
198 |
+
|
199 |
+
msg = "Pomozite mi sa EON uslugama"
|
200 |
+
system_content = "Korisnik User ispod postavlja pitanje ili zadatak, upareno sa unosom koji pruža dodatni mogući kontekst. Napišite odgovor na srpskom jeziku, koji na odgovarajući način kompletira zahtev ili daje odgovor na pitanje. EON je deo usluga preduzeća United Group, koje uključuju i kablovsku mrežu za digitalnu televiziju, pristup internetu, uređaj EON SMART BOX za TV sadržaj, i fiksnu telefoniju. Korisnik se može obratiti Call centru telefonom na 080012341234, ili otiči do najbliže filijale ako mu ne pomaže odgovor."
|
201 |
+
#system_content = "Zoveš se Assistant. Ogovaraj ljubazno na pitanja i probleme koje postavlja korisnik koji se zove User."
|
202 |
+
#msg_content = "odgovori mi na ovo pitanje ili problem kroz sumiranje sledećih delova uputstava, od kojih se samo neka odnose na postavljeno pitanje ili problem: "
|
203 |
+
msg_content = "dodatni mogući kontekts je: "
|
204 |
+
ns = cs = "s0"
|
205 |
+
messages = context = []
|
206 |
+
reply = ctx = ""
|
207 |
+
print ("Recite kako Vam mogu pomoći ...")
|
208 |
+
ctx_flag = True
|
209 |
+
previous = ""
|
210 |
+
while True:
|
211 |
+
print()
|
212 |
+
show = False
|
213 |
+
msg = input("User> ")
|
214 |
+
print()
|
215 |
+
if msg=="###":
|
216 |
+
show = True
|
217 |
+
print("ctx: ", ctx, ", len=", len(context))
|
218 |
+
print("reply=", reply)
|
219 |
+
print("msg: ", messages)
|
220 |
+
msg = input("User> ")
|
221 |
+
print()
|
222 |
+
if msg=="###": break
|
223 |
+
query_results = collection.query(
|
224 |
+
query_texts = [ msg ],
|
225 |
+
n_results = max_results,
|
226 |
+
where = { "$and": [ { "$or": [ {"state": cs }, { "page": { "$nin": [ -1 ] } } ] } , { "used": False } ] }
|
227 |
+
)
|
228 |
+
ln = len(query_results["documents"])
|
229 |
+
ctx = ""
|
230 |
+
context = []
|
231 |
+
for n in range(ln):
|
232 |
+
context += query_results["documents"][n]
|
233 |
+
for n in range(len(context)):
|
234 |
+
ctx += context[n] + ", "
|
235 |
+
ctx = ctx[:-2]
|
236 |
+
if messages==[]:
|
237 |
+
messages=[
|
238 |
+
{"role": "system", "content": system_content},
|
239 |
+
{"role": "user", "content": f"{msg} - " + msg_content + ctx + "."}
|
240 |
+
]
|
241 |
+
else:
|
242 |
+
if ctx_flag:
|
243 |
+
new_message = [
|
244 |
+
{"role": "user", "content": f"{msg}" + msg_content + ctx + "."}
|
245 |
+
]
|
246 |
+
else:
|
247 |
+
new_message = [
|
248 |
+
# {"role": "system", "content": [system_content] + context},
|
249 |
+
# {"role": "user", "content": f"{msg}" + msg_content + ctx + "."}
|
250 |
+
{"role": "user", "content": msg + "."}
|
251 |
+
]
|
252 |
+
messages.append(new_message)
|
253 |
+
if (ln==0):
|
254 |
+
collection.update(
|
255 |
+
ids=[f"id{id}" for id in range(collection.count())],
|
256 |
+
metadatas=[{"used": False} for i in range(collection.count())],
|
257 |
+
)
|
258 |
+
reply = "Kako Vam još mogu pomoći?"
|
259 |
+
ctx_flag = True
|
260 |
+
ns = cs = "s0"
|
261 |
+
elif query_results["documents"][0][0]=="###":
|
262 |
+
ctx_flag = False
|
263 |
+
else:
|
264 |
+
if (query_results["distances"][0][0] > 0.6):
|
265 |
+
ctx_flag = True
|
266 |
+
print("Malo je nejasno šta je problem..")
|
267 |
+
collection.update(
|
268 |
+
ids=[f"id{id}" for id in range(collection.count())],
|
269 |
+
metadatas=[{"used": False} for i in range(collection.count())],
|
270 |
+
)
|
271 |
+
reply = "Kako Vam još mogu pomoći?"
|
272 |
+
ns = cs = "s0"
|
273 |
+
else:
|
274 |
+
ctx_flag = False
|
275 |
+
reply=query_results["documents"][0][0]
|
276 |
+
id = query_results["ids"][0]
|
277 |
+
meta = query_results["metadatas"][0]
|
278 |
+
# ovo treba usloviti potrebnom input var ako treba
|
279 |
+
if (meta[0]["state"] not in ['None','s99']): meta[0]["used"] = True
|
280 |
+
collection.update( ids=id, metadatas=meta)
|
281 |
+
ns = query_results["metadatas"][0][0]["next"]
|
282 |
+
if show: print(cs, "->", ns)
|
283 |
+
if not(show):
|
284 |
+
print(f"Assistant({cs}): ")
|
285 |
+
else:
|
286 |
+
print(f"Assistant({cs}): ", query_results["documents"][0][0]) ; print(messages)
|
287 |
+
completion = oc.chat.completions.create(
|
288 |
+
model = model_id,
|
289 |
+
messages=messages,
|
290 |
+
temperature=0.6, #0.9
|
291 |
+
max_tokens=2048,
|
292 |
+
top_p=0.8, #0.2, 0.92
|
293 |
+
frequency_penalty=0.0, #0.05
|
294 |
+
presence_penalty=0.0, # 1.11
|
295 |
+
stop=None,
|
296 |
+
# do_sampe=True,
|
297 |
+
# stream=True
|
298 |
+
)
|
299 |
+
new_message = {"role": "assistant", "content": ""}
|
300 |
+
new=completion.choices[0].message.content
|
301 |
+
if new==previous:
|
302 |
+
new_message["content"] = reply
|
303 |
+
collection.update(
|
304 |
+
ids=[f"id{id}" for id in range(collection.count())],
|
305 |
+
metadatas=[{"used": False} for i in range(collection.count())],
|
306 |
+
)
|
307 |
+
previous = reply = "Kako Vam još mogu pomoći?"
|
308 |
+
printf (reply, end="", flush=True)
|
309 |
+
ns = cs = "s0"
|
310 |
+
messages=[]
|
311 |
+
else:
|
312 |
+
new_message["content"] += completion.choices[0].message.content
|
313 |
+
previous = new
|
314 |
+
print(new, end="", flush=True)
|
315 |
+
messages.append(new_message)
|
316 |
+
#messages=[]
|
317 |
+
if (ns!='None'):
|
318 |
+
if (ns != cs): cs=ns ; context = [] ; ctx = "" ; ctx_flag = True
|
319 |
+
if cs=='None': cs='s0' ; ctx_flag = False
|
320 |
+
|
321 |
+
print("Kraj.")
|
322 |
+
|
bot/uchat.py
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import chromadb
|
2 |
+
from chromadb.utils import embedding_functions
|
3 |
+
from .models import Param
|
4 |
+
import os
|
5 |
+
import torch
|
6 |
+
from openai import OpenAI
|
7 |
+
from langchain_community.document_loaders import PyPDFLoader
|
8 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
9 |
+
from itertools import islice, zip_longest
|
10 |
+
import re
|
11 |
+
|
12 |
+
# model_id = "mistralai/Mistral-7B-Instruct-v0.2"
|
13 |
+
model_id = "Yugo60-GPT-GGUF.Q4_K_M.gguf"
|
14 |
+
|
15 |
+
#outputs = model.generate(**inputs, max_new_tokens=20)
|
16 |
+
#print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
17 |
+
|
18 |
+
if not torch.backends.mps.is_available():
|
19 |
+
if not torch.backends.mps.is_built():
|
20 |
+
print("MPS not available because the current PyTorch install was not "
|
21 |
+
"built with MPS enabled.")
|
22 |
+
else:
|
23 |
+
print("MPS not available because the current MacOS version is not 12.3+ "
|
24 |
+
"and/or you do not have an MPS-enabled device on this machine.")
|
25 |
+
else:
|
26 |
+
torch.set_default_device("mps")
|
27 |
+
|
28 |
+
model = ""
|
29 |
+
CHROMA_DATA_PATH = "/Users/zoranpopovic/uchat/chroma_data/"
|
30 |
+
EMBED_MODEL = "all-MiniLM-L6-v2"
|
31 |
+
# NousResearch/Hermes-2-Pro-Mistral-7B
|
32 |
+
# distilbert-base-multilingual-case
|
33 |
+
# paraphrase-multilingual-MiniLM-L12-v2d
|
34 |
+
COLLECTION_NAME = "chroma_data"
|
35 |
+
PDF_PATH = "./PDF/uputstvo_uz_eon_smart_box-1.pdf"
|
36 |
+
PDF_PATH2 = "./PDF/uputstvo_uz_eon_smart_aplikaciju-1.pdf"
|
37 |
+
CHUNK_SIZE = 800
|
38 |
+
CHUNK_OVERLAP = 50
|
39 |
+
max_results = 3
|
40 |
+
min_len = 40
|
41 |
+
min_distance = 0.35
|
42 |
+
max_distance = 0.6
|
43 |
+
temperature = 0.55
|
44 |
+
max_tokens=3072
|
45 |
+
top_p=0.8
|
46 |
+
frequency_penalty=0.0
|
47 |
+
presence_penalty=0.15
|
48 |
+
DEBUG = True
|
49 |
+
system_sr = "Zoveš se U-Chat AI asistent i pomažeš korisniku usluga kompanije United Group. Korisnik postavlja pitanje ili problem, upareno sa dodatnima saznanjima. Na osnovu toga napiši korisniku kratak i ljubazan odgovor koji kompletira njegov zahtev ili mu daje odgovor na pitanje. "
|
50 |
+
# " Ako ne znaš odgovor, reci da ne znaš, ne izmišljaj ga."
|
51 |
+
system_sr += "Usluge kompanije United Group uključuju i kablovsku mrežu za digitalnu televiziju, pristup internetu, uređaj EON SMART BOX za TV sadržaj, kao i fiksnu telefoniju."
|
52 |
+
system = {'srpski': system_sr, 'hrvatski': "", 'slovenački': "", 'makedonski': ""}
|
53 |
+
ctxpre = ""
|
54 |
+
msg_content = {'srpski': "- Dodatna saznanja su: ", 'hrvatski': "", 'slovenački': "", 'makedonski': ""}
|
55 |
+
max_conv = 3
|
56 |
+
try:
|
57 |
+
edit_all = Param.objects.all()
|
58 |
+
for edit in edit_all:
|
59 |
+
system[edit.jezik] = edit.system
|
60 |
+
ctxpre = edit.ctxpre
|
61 |
+
msg_content[edit.jezik] = edit.msg_content
|
62 |
+
min_len = edit.min_len
|
63 |
+
CHUNK_SIZE = edit.CHUNK_SIZE
|
64 |
+
CHUNK_OVERLAP = edit.CHUNK_OVERLAP
|
65 |
+
max_results = edit.max_results
|
66 |
+
EMBED_MODEL = edit.EMBED_MODEL
|
67 |
+
model_id = edit.model_id
|
68 |
+
min_distance = edit.min_distance
|
69 |
+
max_distance = edit.max_distance
|
70 |
+
max_conv = edit.max_conv
|
71 |
+
temperature = edit.temperature
|
72 |
+
top_p = edit.top_p
|
73 |
+
max_tokens = edit.max_tokens
|
74 |
+
presence_penalty = edit.presence_penalty
|
75 |
+
frequency_penalty = edit.frequency_penalty
|
76 |
+
DEBUG = edit.DEBUG
|
77 |
+
except:
|
78 |
+
pass
|
79 |
+
|
80 |
+
def load_and_split_document(pdf_path):
|
81 |
+
loader = PyPDFLoader(pdf_path)
|
82 |
+
print('Loaded: ' + pdf_path)
|
83 |
+
return loader.load_and_split()
|
84 |
+
|
85 |
+
def split_text_into_chunks(pages, chunk_size, chunk_overlap):
|
86 |
+
n = -1
|
87 |
+
for page in range(len(pages)): pages[page].page_content = re.sub(r'\s+'," ", pages[page].page_content.replace(". .","").replace(r'\n','.')).replace('..','')
|
88 |
+
for p in range(len(pages)):
|
89 |
+
if len(pages[p].page_content)<min_len:
|
90 |
+
if n<0: n = p
|
91 |
+
else:
|
92 |
+
if n>=0:
|
93 |
+
pages[n]=pages[p]; n += 1
|
94 |
+
if n>0: pages = pages[:n-1]
|
95 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap)
|
96 |
+
return text_splitter.split_documents(pages)
|
97 |
+
|
98 |
+
def batched(iterable, n):
|
99 |
+
it = iter(iterable)
|
100 |
+
while True:
|
101 |
+
batch = list(islice(it, n))
|
102 |
+
if not batch:
|
103 |
+
return
|
104 |
+
yield batch
|
105 |
+
|
106 |
+
#client = chromadb.PersistentClient(path=CHROMA_DATA_PATH)
|
107 |
+
#client.allow_reset = True
|
108 |
+
#client.delete_collection(COLLECTION_NAME)
|
109 |
+
oc = OpenAI(base_url="http://localhost:4891/v1", api_key="not-needed")
|
110 |
+
|
111 |
+
chroma_client = chromadb.PersistentClient(CHROMA_DATA_PATH)
|
112 |
+
|
113 |
+
embedding_func = embedding_functions.SentenceTransformerEmbeddingFunction(
|
114 |
+
model_name=EMBED_MODEL
|
115 |
+
)
|
116 |
+
|
117 |
+
collection = chroma_client.get_or_create_collection(
|
118 |
+
name="chroma_data",
|
119 |
+
embedding_function=embedding_func,
|
120 |
+
metadata={"hnsw:space": "cosine"},
|
121 |
+
)
|
122 |
+
|
123 |
+
last = collection.count()
|
124 |
+
|
125 |
+
def update_collection(docs, last, jezik):
|
126 |
+
state = -2
|
127 |
+
used =[]
|
128 |
+
for g in docs[0::2]:
|
129 |
+
state += 2
|
130 |
+
documents=docs[state+1][0]
|
131 |
+
bot.uchat.collection.add(
|
132 |
+
documents=documents,
|
133 |
+
ids=[f"id{last+i}" for i in range(len(documents))],
|
134 |
+
metadatas=[{"state": g, "next": g, "used": False, "source": 'None', "page": -1, "lang": jezik } for i in range(len(documents)) ]
|
135 |
+
)
|
136 |
+
last += len(documents)
|
137 |
+
if (len(docs[state+1])>1):
|
138 |
+
for n in docs[state+1][1:]:
|
139 |
+
bot.uchat.collection.add(
|
140 |
+
documents=n[1:],
|
141 |
+
ids=[f"id{last+i-1}" for i in range(1,len(n))],
|
142 |
+
metadatas=[{"state": g, "next": n[0], "used": False, "source": 'None', "page": -1, "lang": jezik } for i in range(1,len(n)) ]
|
143 |
+
)
|
144 |
+
for i in range(1,len(n)): used += [0]
|
145 |
+
last += len(n)-1
|
146 |
+
return last
|
147 |
+
|
148 |
+
#docus = load_and_split_document(PDF_PATH) + load_and_split_document(PDF_PATH2)
|
149 |
+
|
150 |
+
def load_docs(path, jezik):
|
151 |
+
docus = load_and_split_document(path)
|
152 |
+
pages = split_text_into_chunks(docus, CHUNK_SIZE, CHUNK_OVERLAP)
|
153 |
+
document_indices = list(range(bot.uchat.last, bot.uchat.last+len(pages)))
|
154 |
+
for batch in batched(document_indices, 66):
|
155 |
+
bot.uchat.collection.add(
|
156 |
+
ids=[f"id{last+batch[i]}" for i in range(len(batch))],
|
157 |
+
documents=[pages[i].page_content for i in batch],
|
158 |
+
metadatas=[dict(dict(dict(dict(pages[i].metadata, used=False), next='None'), state='None'), lang=jezik) for i in batch],
|
159 |
+
)
|
160 |
+
last += len(batch)
|
161 |
+
return last
|
162 |
+
|
bot/urls.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.urls import path
|
2 |
+
from . import views
|
3 |
+
#from . import tests
|
4 |
+
|
5 |
+
urlpatterns = [
|
6 |
+
path('', views.index, name='index'),
|
7 |
+
path('bot/', views.editor, name='bot'),
|
8 |
+
]
|
9 |
+
|
10 |
+
urlpatterns += [
|
11 |
+
path('reset/', views.reset, name='reset'),
|
12 |
+
]
|
13 |
+
|
14 |
+
urlpatterns += [
|
15 |
+
path('languages/', views.BotView.as_view(), name='languages'),
|
16 |
+
path('language/<int:pk>', views.BotViewDetail.as_view(), name='bot-detail'),
|
17 |
+
path('bot/<int:pk>/<int:pk2>', views.editor_id, name='editor_id'),
|
18 |
+
path('params/', views.params, name='params'),
|
19 |
+
path('params/0', views.params_refresh, name='params-refresh'),
|
20 |
+
path('importpdf', views.importPdf, name='importpdf'),
|
21 |
+
# path('bot/create', views.editor_create, name='editor_create'),
|
22 |
+
# path('bot/delete', views.editor_delete, name='editor_delete'),
|
23 |
+
]
|
24 |
+
|
25 |
+
#urlpatterns += [
|
26 |
+
# path('tests/', views.LanguageViewTest.as_view(), name='tests'),
|
27 |
+
#]
|
28 |
+
|
29 |
+
#urlpatterns += [
|
30 |
+
# path('tests/', views.UserViewTest.as_view(), name='tests'),
|
31 |
+
#]
|
bot/views.py
ADDED
@@ -0,0 +1,624 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import bot.uchat
|
2 |
+
from django.shortcuts import render
|
3 |
+
from .models import Language, Query, ParamModelForm, Param
|
4 |
+
from bot.forms import RenewBotForm, EditorForm, EditorListForm, ParamForm, ImportForm
|
5 |
+
from django.shortcuts import get_object_or_404
|
6 |
+
from django.http import HttpResponseRedirect
|
7 |
+
from django.urls import reverse
|
8 |
+
import datetime
|
9 |
+
from django.db import transaction
|
10 |
+
from openai import OpenAI
|
11 |
+
from django.contrib.auth.decorators import login_required, permission_required
|
12 |
+
import json
|
13 |
+
|
14 |
+
#bot.uchat.chroma_client.allow_reset = True
|
15 |
+
|
16 |
+
class chat(object):
|
17 |
+
ns = cs = "s0"
|
18 |
+
reply = ctx = ""
|
19 |
+
messages = context = []
|
20 |
+
ctx_flag = True
|
21 |
+
previous = ""
|
22 |
+
oc = bot.uchat.oc
|
23 |
+
def get_reply(self,jezik,query,max_results,flag):
|
24 |
+
msg = query # + "Objasnite na " + jezik + ", "
|
25 |
+
query_results = bot.uchat.collection.query(
|
26 |
+
query_texts = [ msg ],
|
27 |
+
n_results = max_results,
|
28 |
+
where = { "$and": [ {"$and": [ { "$or": [ {"state": self.cs }, { "page": { "$nin": [ -1 ] } } ] } , { "used": False } ] } ,
|
29 |
+
{"lang": jezik } ] },
|
30 |
+
)
|
31 |
+
if bot.uchat.DEBUG: print("Query results:\n", query_results, "jezik:", jezik)
|
32 |
+
ln = len(query_results["documents"][0])
|
33 |
+
if ln == 0:
|
34 |
+
if bot.uchat.DEBUG: print("Odaberite drugi jezik")
|
35 |
+
bot.uchat.collection.update(
|
36 |
+
ids=[f"id{id}" for id in range(bot.uchat.collection.count())],
|
37 |
+
metadatas=[{"used": False} for i in range(bot.uchat.collection.count())],
|
38 |
+
)
|
39 |
+
if len(self.messages)>0: self.messages = self.messages[0]
|
40 |
+
new = reply = "Kako Vam još mogu pomoći?"
|
41 |
+
self.ctx_flag = True
|
42 |
+
self.ns = self.cs = "s0"
|
43 |
+
return new
|
44 |
+
else:
|
45 |
+
context = []
|
46 |
+
i_state = l_state = -1
|
47 |
+
for n in range(ln):
|
48 |
+
if query_results["distances"][0][n] < (0.05+(bot.uchat.max_distance+bot.uchat.min_distance)/2):
|
49 |
+
context += [ query_results["documents"][0][n] ]
|
50 |
+
if i_state<0:
|
51 |
+
l_state += 1
|
52 |
+
if query_results["metadatas"][0][n]['state'] != 'None':
|
53 |
+
i_state = n
|
54 |
+
else:
|
55 |
+
if (query_results["metadatas"][0][n]['state'] != 'None') and (i_state<0):
|
56 |
+
i_state = n
|
57 |
+
if l_state<0:
|
58 |
+
l_state = i_state = 0
|
59 |
+
ctx = query_results["documents"][0][0]
|
60 |
+
if self.cs != 'None':
|
61 |
+
for n in range(1,len(context)): ctx += ", " + context[n]
|
62 |
+
else:
|
63 |
+
ctx = context[l_state]
|
64 |
+
for n in range(len(context)):
|
65 |
+
if l_state != n:
|
66 |
+
ctx += ", " + context[n]
|
67 |
+
ctx += "."
|
68 |
+
match jezik:
|
69 |
+
case 'hrvatski':
|
70 |
+
o_jezik = 'hrvatskom'
|
71 |
+
case 'slovenački':
|
72 |
+
o_jezik = 'slovenačkom'
|
73 |
+
case 'srpski':
|
74 |
+
o_jezik = 'srpskom'
|
75 |
+
case 'makedonski':
|
76 |
+
o_jezik = 'makedonskom'
|
77 |
+
if query_results["documents"][0][i_state]=="###":
|
78 |
+
self.ctx_flag = False
|
79 |
+
new = reply = "Kako Vam još mogu pomoći?"
|
80 |
+
if bot.uchat.DEBUG: print("!!!###!!!")
|
81 |
+
return "Ne razumem, ili je u pitanju greška."
|
82 |
+
else:
|
83 |
+
if ((query_results["distances"][0][i_state] > bot.uchat.max_distance)) and (self.cs == 'None'):
|
84 |
+
self.ctx_flag = False
|
85 |
+
if bot.uchat.DEBUG: print("Malo je nejasno šta je problem..")
|
86 |
+
bot.uchat.collection.update(
|
87 |
+
ids=[f"id{id}" for id in range(bot.uchat.collection.count())],
|
88 |
+
metadatas=[{"used": False} for i in range(bot.uchat.collection.count())],
|
89 |
+
)
|
90 |
+
if len(messages)>0: messsages = messages[0]
|
91 |
+
reply = "Malo je nejasno šta je problem - kako Vam još mogu pomoći?"
|
92 |
+
self.ns = self.cs = "s0"
|
93 |
+
return reply
|
94 |
+
elif (query_results["distances"][0][i_state] < bot.uchat.min_distance):
|
95 |
+
if self.cs != "None":
|
96 |
+
self.ctx_flag = False
|
97 |
+
else:
|
98 |
+
self.ctx_flag = True
|
99 |
+
new = reply=query_results["documents"][0][i_state]
|
100 |
+
else:
|
101 |
+
self.ctx_flag = True
|
102 |
+
# reply=query_results["documents"][0][i_state]
|
103 |
+
if (len(msg) < bot.uchat.min_len/4) or flag: self.ctx_flag = False
|
104 |
+
id = query_results["ids"][0]
|
105 |
+
meta = query_results["metadatas"][0]
|
106 |
+
# ovo treba usloviti potrebnom input var ako treba
|
107 |
+
if (meta[i_state]["state"] not in ['','s99']): meta[0]["used"] = True
|
108 |
+
bot.uchat.collection.update( ids=id, metadatas=meta)
|
109 |
+
self.ns = query_results["metadatas"][0][i_state]["next"]
|
110 |
+
if self.messages==[]:
|
111 |
+
self.messages = [ {"role": "system", "content": bot.uchat.system[jezik]} ]
|
112 |
+
new_message = {"role": "user", "content": f"{msg} " + bot.uchat.msg_content[jezik] + " " + ctx + ". "}
|
113 |
+
else:
|
114 |
+
if self.ctx_flag:
|
115 |
+
new_message = {"role": "user", "content": f"{msg}. " + bot.uchat.msg_content[jezik] + " " + ctx + ". "}
|
116 |
+
else:
|
117 |
+
new_message = {"role": "user", "content": f"{msg}."}
|
118 |
+
self.messages.append(new_message)
|
119 |
+
print("messages=", self.messages)
|
120 |
+
if query_results["distances"][0][i_state] > bot.uchat.min_distance:
|
121 |
+
completion = bot.uchat.oc.chat.completions.create(
|
122 |
+
model = bot.uchat.model_id,
|
123 |
+
messages=self.messages,
|
124 |
+
temperature=bot.uchat.temperature,
|
125 |
+
max_tokens=bot.uchat.max_tokens,
|
126 |
+
top_p=bot.uchat.top_p,
|
127 |
+
frequency_penalty=bot.uchat.frequency_penalty,
|
128 |
+
presence_penalty=bot.uchat.presence_penalty,
|
129 |
+
stop=["###","<|","|im_end|","|im_start|"],
|
130 |
+
# do_sample=True,
|
131 |
+
)
|
132 |
+
if bot.uchat.DEBUG: print('msg=' + new_message['content'] + "\nMessages:\n", self.messages, flush=True)
|
133 |
+
new_message = {"role": "assistant", "content": ""}
|
134 |
+
new=completion.choices[0].message.content
|
135 |
+
if new==self.previous:
|
136 |
+
if bot.uchat.DEBUG: print("Same!!!")
|
137 |
+
bot.uchat.collection.update(
|
138 |
+
ids=[f"id{id}" for id in range(bot.uchat.collection.count())],
|
139 |
+
metadatas=[{"used": False} for i in range(bot.uchat.collection.count())],
|
140 |
+
)
|
141 |
+
new_message["content"] = new = self.previous = reply = "Kako Vam još mogu pomoći?"
|
142 |
+
self.ns = self.cs = "s0"
|
143 |
+
self.messages = self.messages[0]
|
144 |
+
else:
|
145 |
+
new_message["content"] += completion.choices[0].message.content
|
146 |
+
self.previous = new_message["content"]
|
147 |
+
if bot.uchat.DEBUG: print(new, end="", flush=True)
|
148 |
+
else:
|
149 |
+
new_message = {"role": "assistant", "content": ""}
|
150 |
+
new_message["content"] = reply
|
151 |
+
new = reply
|
152 |
+
self.messages.append(new_message)
|
153 |
+
# Prevođenje na druge jezike:
|
154 |
+
#match o_jezik:
|
155 |
+
# case 'srpskom':
|
156 |
+
# pass
|
157 |
+
# case _ :
|
158 |
+
# new_message = {"role": "user", "content": f"Napiši to na {o_jezik} jeziku."}
|
159 |
+
# self.messages.append(new_message)
|
160 |
+
# completion = bot.uchat.oc.chat.completions.create(
|
161 |
+
# model = bot.uchat.model_id,
|
162 |
+
# messages=self.messages,
|
163 |
+
# temperature=bot.uchat.temperature,
|
164 |
+
# max_tokens=bot.uchat.max_tokens,
|
165 |
+
# top_p=bot.uchat.top_p,
|
166 |
+
# frequency_penalty=bot.uchat.frequency_penalty,
|
167 |
+
# presence_penalty=bot.uchat.presence_penalty,
|
168 |
+
# stop=None,
|
169 |
+
# # do_sample=True,
|
170 |
+
# )
|
171 |
+
# new=completion.choices[0].message.content
|
172 |
+
# new_message = {"role": "user", "content": new}
|
173 |
+
# self.messages.append(new_message)
|
174 |
+
if (self.ns!='None'):
|
175 |
+
if (self.ns != self.cs): self.cs=self.ns
|
176 |
+
if self.cs=='None': self.cs='s0' ; self.ctx_flag = False
|
177 |
+
return new
|
178 |
+
|
179 |
+
def selected(jez,str):
|
180 |
+
if jez==str:
|
181 |
+
return 'selected'
|
182 |
+
else:
|
183 |
+
return ' '
|
184 |
+
|
185 |
+
def index(request):
|
186 |
+
#num_books = Book.objects.all().count()
|
187 |
+
# Number of visits to this view, as counted in the session variable.
|
188 |
+
chat_inst = chat()
|
189 |
+
request.session.set_expiry(300)
|
190 |
+
jezik = request.session.get('jezik', 'srpski')
|
191 |
+
num_visits = request.session.get('num_visits', 1)
|
192 |
+
if num_visits == 0:
|
193 |
+
if bot.uchat.DEBUG: print("Debug: ")
|
194 |
+
request.session['num_visits'] = num_visits+1
|
195 |
+
reply = request.session.get("replies", "Zdravo, kako Vam mogu pomoći?")
|
196 |
+
if request.method == 'POST':
|
197 |
+
# Create a form instance and populate it with data from the request (binding):
|
198 |
+
form = RenewBotForm(request.POST)
|
199 |
+
if form.is_valid():
|
200 |
+
request.session['query'] = query = form.cleaned_data['query']
|
201 |
+
jezik = form.cleaned_data['jezik']
|
202 |
+
request.session['jezik'] = jezik
|
203 |
+
nr = bot.uchat.max_results if num_visits < bot.uchat.max_results else 1+(num_visits % 2)
|
204 |
+
#iif len(chat_inst.messages)>0:
|
205 |
+
# request.session['messages'] = chat_inst.messages if num_visits % 2 == 1 else chat_inst.messages[0:0]
|
206 |
+
chat_inst.messages = request.session.get('messages',[])
|
207 |
+
chat_inst.cs = request.session.get('cs','s0')
|
208 |
+
chat_inst.ns = request.session.get('ns','s0')
|
209 |
+
if bot.uchat.max_conv < len(chat_inst.messages):
|
210 |
+
new_reply = chat_inst.get_reply(jezik, query, nr, True)
|
211 |
+
else:
|
212 |
+
new_reply = chat_inst.get_reply(jezik, query, nr, False)
|
213 |
+
request.session['messages'] = chat_inst.messages
|
214 |
+
request.session['ns'] = chat_inst.ns
|
215 |
+
request.session['cs'] = chat_inst.cs
|
216 |
+
request.session['replies'] = reply + "\nKorisnik: " + query + "\n\nOdgovor: " + new_reply + "\n"
|
217 |
+
# q = QueryForm(request.POST)
|
218 |
+
return HttpResponseRedirect(reverse("index"))
|
219 |
+
else:
|
220 |
+
if bot.uchat.DEBUG: print("Invalid form!", form.errors)
|
221 |
+
else:
|
222 |
+
form = RenewBotForm(initial={'query': 'Neki upit:'})
|
223 |
+
query = request.session.get('query','...')
|
224 |
+
jezik = request.session.get('jezik','srpski')
|
225 |
+
#if len(chat_inst.messages)>0:
|
226 |
+
# request.session['messages'] = chat_inat.messages
|
227 |
+
#else:
|
228 |
+
# request.session['messages'] = []
|
229 |
+
return render(
|
230 |
+
request,
|
231 |
+
'index.html',
|
232 |
+
context={
|
233 |
+
'num_visits': num_visits,
|
234 |
+
'reply': reply,
|
235 |
+
'selected_hr': selected(jezik,'hrvatski'),
|
236 |
+
'selected_sl': selected(jezik,'slovenački'),
|
237 |
+
'selected_sr': selected(jezik,'srpski'),
|
238 |
+
'selected_mk': selected(jezik,'makedonski'),
|
239 |
+
}
|
240 |
+
)
|
241 |
+
|
242 |
+
def reset(request):
|
243 |
+
chat().messages = request.session.get('messages',[])
|
244 |
+
chat().cs = "s0"
|
245 |
+
chat().ns = "s0"
|
246 |
+
chat().oc.close()
|
247 |
+
bot.uchat.oc = oc = OpenAI(base_url="http://localhost:4891/v1", api_key="not-needed")
|
248 |
+
ids = bot.uchat.collection.get()['ids']
|
249 |
+
for id in ids: bot.uchat.collection.update(ids=[id], metadatas=[{'used': False}])
|
250 |
+
jezik = request.session.get('jezik','srpski')
|
251 |
+
request.session.flush()
|
252 |
+
request.session['num_visits'] = 0
|
253 |
+
return render(
|
254 |
+
request,
|
255 |
+
'index.html',
|
256 |
+
context = {'num_visits': 0,
|
257 |
+
'reply': 'Kako Vam mogu još pomoći?',
|
258 |
+
'selected_hr': selected(jezik,'hrvatski'),
|
259 |
+
'selected_sl': selected(jezik,'slovenački'),
|
260 |
+
'selected_sr': selected(jezik,'srpski'),
|
261 |
+
'selected_mk': selected(jezik,'makedonski'),
|
262 |
+
}
|
263 |
+
)
|
264 |
+
|
265 |
+
def editor(request):
|
266 |
+
#pagesize = 10
|
267 |
+
if request.method == "POST":
|
268 |
+
form = EditorListForm(request.POST)
|
269 |
+
form.is_valid()
|
270 |
+
try:
|
271 |
+
request.session['id'] = f_id = form.cleaned_data['f_id']
|
272 |
+
except:
|
273 |
+
request.session['id'] = f_id = ""
|
274 |
+
try:
|
275 |
+
request.session['state'] = f_state = form.cleaned_data['f_state']
|
276 |
+
except:
|
277 |
+
request.session['state'] = f_state = ""
|
278 |
+
try:
|
279 |
+
request.session['next'] = f_next = form.cleaned_data['f_next']
|
280 |
+
except:
|
281 |
+
request.session['next'] = f_next = ""
|
282 |
+
try:
|
283 |
+
request.session['page'] = f_page = form.cleaned_data['f_page']
|
284 |
+
except:
|
285 |
+
request.session['page'] = f_page = ""
|
286 |
+
try:
|
287 |
+
request.session['jezik'] = f_jezik = form.cleaned_data['f_jezik']
|
288 |
+
except:
|
289 |
+
request.session['jezik'] = f_jezik = ""
|
290 |
+
try:
|
291 |
+
request.session['docu'] = f_docu = form.cleaned_data['f_docu']
|
292 |
+
except:
|
293 |
+
request.session['docu'] = f_docu = ""
|
294 |
+
return HttpResponseRedirect(reverse('bot'))
|
295 |
+
else:
|
296 |
+
f_jezik = jezik = request.session.get('jezik','')
|
297 |
+
f_state = request.session.get('state','')
|
298 |
+
f_next = request.session.get('next','')
|
299 |
+
f_page = request.session.get('page','')
|
300 |
+
f_docu = request.session.get('docu','')
|
301 |
+
f_id = request.session.get('id','')
|
302 |
+
meta = {}
|
303 |
+
if f_state != "":
|
304 |
+
meta = {"state": f_state}
|
305 |
+
if f_next != "":
|
306 |
+
if meta == {}:
|
307 |
+
meta = {"next": f_next}
|
308 |
+
else:
|
309 |
+
meta = { "$and": [ meta, {"next": f_next} ] }
|
310 |
+
if f_page !="":
|
311 |
+
if meta == {}:
|
312 |
+
meta = {"page": f_page}
|
313 |
+
else:
|
314 |
+
meta = { "$and": [ meta , {"page": f_page} ] }
|
315 |
+
if f_jezik != "":
|
316 |
+
if meta == {}:
|
317 |
+
meta = {"lang": f_jezik}
|
318 |
+
else:
|
319 |
+
meta = { "$and": [ meta, {"lang": f_jezik} ] }
|
320 |
+
if f_id == "":
|
321 |
+
if f_docu =="":
|
322 |
+
ids = bot.uchat.collection.get(where=meta)['ids']
|
323 |
+
documents = bot.uchat.collection.get(where=meta)['documents']
|
324 |
+
states = bot.uchat.collection.get(where=meta)['metadatas']
|
325 |
+
else:
|
326 |
+
ids = bot.uchat.collection.get(where=meta, where_document={"$contains": f_docu })['ids']
|
327 |
+
documents = bot.uchat.collection.get(where=meta, where_document={"$contains": f_docu })['documents']
|
328 |
+
states = bot.uchat.collection.get(where=meta, where_document={"$contains": f_docu })['metadatas']
|
329 |
+
else:
|
330 |
+
if f_docu == "":
|
331 |
+
ids = bot.uchat.collection.get(ids=[f'id{f_id}'], where=meta)['ids']
|
332 |
+
documents = bot.uchat.collection.get(ids=[f'id{f_id}'], where=meta)['documents']
|
333 |
+
states = bot.uchat.collection.get(ids=[f'id{f_id}'], where=meta)['metadatas']
|
334 |
+
else:
|
335 |
+
ids = bot.uchat.collection.get(ids=[f'id{f_id}'], where=meta, where_document={"$contains": f_docu })['ids']
|
336 |
+
documents = bot.uchat.collection.get(ids=[f'id{f_id}'], where=meta, where_document={"$contains": f_docu })['documents']
|
337 |
+
states = bot.uchat.collection.get(ids=[f'id{f_id}'], where=meta, where_document={"$contains": f_docu })['metadatas']
|
338 |
+
cnt = 0
|
339 |
+
nr = len(documents)
|
340 |
+
id_docs = []
|
341 |
+
for doc in documents:
|
342 |
+
try:
|
343 |
+
lang = states[cnt]['lang']
|
344 |
+
except:
|
345 |
+
lang = "srpski"
|
346 |
+
id_docs += [ [ids[cnt], states[cnt]['state'], states[cnt]['next'], states[cnt]['page'], lang, doc] ]
|
347 |
+
cnt += 1
|
348 |
+
id_docs.sort(key=lambda k: eval(k[0][2:]))
|
349 |
+
return render(
|
350 |
+
request,
|
351 |
+
'index_editor.html',
|
352 |
+
context = {'last': bot.uchat.last, 'nr': nr,
|
353 |
+
'id_docs': id_docs,
|
354 |
+
'documents': documents,
|
355 |
+
'id': "",
|
356 |
+
'selected_hr': selected(jezik,'hrvatski'),
|
357 |
+
'selected_sl': selected(jezik,'slovenački'),
|
358 |
+
'selected_sr': selected(jezik,'srpski'),
|
359 |
+
'selected_mk': selected(jezik,'makedonski'),
|
360 |
+
'f_id': f_id,
|
361 |
+
'f_state': f_state,
|
362 |
+
'f_next': f_next,
|
363 |
+
'f_page': f_page,
|
364 |
+
'f_docu': f_docu,
|
365 |
+
'f_jezik': f_jezik,
|
366 |
+
}
|
367 |
+
)
|
368 |
+
|
369 |
+
def get_id(coll):
|
370 |
+
for i in range(coll.count()):
|
371 |
+
id = coll.get(ids=f'id{i}')['ids']
|
372 |
+
if id==[]:
|
373 |
+
return i
|
374 |
+
return coll.count()
|
375 |
+
|
376 |
+
def editor_id(request, pk, pk2):
|
377 |
+
last = bot.uchat.last
|
378 |
+
state = next = uris = ""
|
379 |
+
used = False
|
380 |
+
page = -1
|
381 |
+
if request.method == "POST":
|
382 |
+
form = EditorForm(request.POST)
|
383 |
+
if form.is_valid():
|
384 |
+
id = form.cleaned_data['id'][2:]
|
385 |
+
state = form.cleaned_data['state']
|
386 |
+
next = form.cleaned_data['next']
|
387 |
+
used = json.loads(form.cleaned_data['used'].lower())
|
388 |
+
page = form.cleaned_data['page']
|
389 |
+
docu = form.cleaned_data['docu']
|
390 |
+
source = form.cleaned_data['source']
|
391 |
+
jezik = form.cleaned_data['jezik']
|
392 |
+
#request.session['jezik'] = jezik
|
393 |
+
meta = {'state': state, 'next': next, 'used': used, 'page': page, 'source': source, 'lang': jezik}
|
394 |
+
try:
|
395 |
+
if pk2==0:
|
396 |
+
bot.uchat.collection.update(
|
397 |
+
ids = f'id{pk}',
|
398 |
+
metadatas = meta,
|
399 |
+
documents = docu
|
400 |
+
)
|
401 |
+
return HttpResponseRedirect(reverse('bot')+f'{pk}/0')
|
402 |
+
elif pk2==1:
|
403 |
+
if bot.uchat.last>1:
|
404 |
+
new = get_id(bot.uchat.collection)
|
405 |
+
bot.uchat.collection.add(
|
406 |
+
ids = f'id{new}',
|
407 |
+
metadatas = meta,
|
408 |
+
documents = docu
|
409 |
+
)
|
410 |
+
bot.uchat.last += 1
|
411 |
+
return HttpResponseRedirect(reverse('bot')+f'{new}/0')
|
412 |
+
elif pk2==2:
|
413 |
+
bot.uchat.collection.delete(ids = f'id{pk}')
|
414 |
+
bot.uchat.last -= 1
|
415 |
+
return HttpResponseRedirect(reverse('bot'))
|
416 |
+
except:
|
417 |
+
if bot.uchat.DEBUG: print("Errors:", form.errors)
|
418 |
+
return HttpResponseRedirect(reverse('bot'))
|
419 |
+
else:
|
420 |
+
if bot.uchat.DEBUG: print("Invalid form!", form.errors)
|
421 |
+
return HttpResponseRedirect(reverse('bot')+f'{pk}/0')
|
422 |
+
else:
|
423 |
+
if last>0:
|
424 |
+
doc = bot.uchat.collection.get(ids=[f'id{pk}'])
|
425 |
+
state = doc['metadatas'][0]['state']
|
426 |
+
next = doc['metadatas'][0]['next']
|
427 |
+
used = doc['metadatas'][0]['used']
|
428 |
+
page = doc['metadatas'][0]['page']
|
429 |
+
docu = doc['documents'][0]
|
430 |
+
source = doc['metadatas'][0]['source']
|
431 |
+
try:
|
432 |
+
jezik = doc['metadatas'][0]['lang']
|
433 |
+
except:
|
434 |
+
jezik = request.session.get('jezik','srpski')
|
435 |
+
return render(
|
436 |
+
request,
|
437 |
+
'index_editor.html',
|
438 |
+
context = {'last': bot.uchat.last, 'nr': "",
|
439 |
+
'state': state,
|
440 |
+
'next': next,
|
441 |
+
'used': used,
|
442 |
+
'page': page,
|
443 |
+
'docu': docu,
|
444 |
+
'source': source,
|
445 |
+
'id': pk,
|
446 |
+
'selected_hr': selected(jezik,'hrvatski'),
|
447 |
+
'selected_sl': selected(jezik,'slovenački'),
|
448 |
+
'selected_sr': selected(jezik,'srpski'),
|
449 |
+
'selected_mk': selected(jezik,'makedonski'),
|
450 |
+
}
|
451 |
+
)
|
452 |
+
|
453 |
+
def params_refresh(request):
|
454 |
+
if request.method == "POST":
|
455 |
+
form = ParamForm(request.POST)
|
456 |
+
form.is_valid()
|
457 |
+
request.session["jezik"] = form.cleaned_data['jezik']
|
458 |
+
return HttpResponseRedirect(reverse('params'))
|
459 |
+
else:
|
460 |
+
return HttpResponseRedirect(reverse('params'))
|
461 |
+
|
462 |
+
def params(request):
|
463 |
+
if request.method == "POST":
|
464 |
+
form = ParamForm(request.POST)
|
465 |
+
jezici = []
|
466 |
+
edit_all = Param.objects.all()
|
467 |
+
for edit in edit_all: jezici += [edit.jezik]
|
468 |
+
mform = ParamModelForm(request.POST)
|
469 |
+
try:
|
470 |
+
form.is_valid()
|
471 |
+
request.session["jezik"] = form.cleaned_data['jezik']
|
472 |
+
jezik = request.session["jezik"]
|
473 |
+
bot.uchat.ctxpre = form.cleaned_data['ctxpre']
|
474 |
+
except:
|
475 |
+
bot.uchat.ctxpre = ""
|
476 |
+
try:
|
477 |
+
bot.uchat.msg_content[jezik] = form.cleaned_data['msg_content']
|
478 |
+
except:
|
479 |
+
bot.uchat.msg_content[jezik] = ""
|
480 |
+
try:
|
481 |
+
bot.uchat.system[jezik] = form.cleaned_data['system']
|
482 |
+
bot.uchat.min_len = form.cleaned_data['min_len']
|
483 |
+
bot.uchat.CHUNK_SIZE = form.cleaned_data['CHUNK_SIZE']
|
484 |
+
bot.uchat.CHUNK_OVERLAP = form.cleaned_data['CHUNK_OVERLAP']
|
485 |
+
bot.uchat.max_results = form.cleaned_data['max_results']
|
486 |
+
bot.uchat.EMBED_MODEL = form.cleaned_data['EMBED_MODEL']
|
487 |
+
bot.uchat.model_id = form.cleaned_data['model_id']
|
488 |
+
bot.uchat.max_conv = form.cleaned_data['max_conv']
|
489 |
+
bot.uchat.min_distance = form.cleaned_data['min_distance']
|
490 |
+
bot.uchat.max_distance = form.cleaned_data['max_distance']
|
491 |
+
bot.uchat.temperature = form.cleaned_data['temperature']
|
492 |
+
bot.uchat.max_tokens = form.cleaned_data['max_tokens']
|
493 |
+
bot.uchat.top_p = form.cleaned_data['top_p']
|
494 |
+
bot.uchat.frequency_penalty = form.cleaned_data['frequency_penalty']
|
495 |
+
bot.uchat.presence_penalty = form.cleaned_data['presence_penalty']
|
496 |
+
bot.uchat.DEBUG = json.loads(form.cleaned_data['DEBUG'].lower())
|
497 |
+
except:
|
498 |
+
if bot.uchat.DEBUG: print("Errors:", form.errors)
|
499 |
+
if jezik in jezici:
|
500 |
+
for edit in edit_all:
|
501 |
+
if edit.jezik == jezik:
|
502 |
+
edit.system = bot.uchat.system[jezik]
|
503 |
+
edit.min_len = bot.uchat.min_len
|
504 |
+
edit.CHUNK_SIZE = bot.uchat.CHUNK_SIZE
|
505 |
+
edit.CHUNK_OVERLAP = bot.uchat.CHUNK_OVERLAP
|
506 |
+
edit.max_results = bot.uchat.max_results
|
507 |
+
edit.EMBED_MODEL = bot.uchat.EMBED_MODEL
|
508 |
+
edit.model_id = bot.uchat.model_id
|
509 |
+
edit.max_conv = bot.uchat.max_conv
|
510 |
+
edit.min_distance = bot.uchat.min_distance
|
511 |
+
edit.max_distance = bot.uchat.max_distance
|
512 |
+
edit.temperature = bot.uchat.temperature
|
513 |
+
edit.max_tokens = bot.uchat.max_tokens
|
514 |
+
edit.top_p = bot.uchat.top_p
|
515 |
+
edit.frequency_penalty = bot.uchat.frequency_penalty
|
516 |
+
edit.presence_penalty = bot.uchat.presence_penalty
|
517 |
+
edit.DEBUG = bot.uchat.DEBUG
|
518 |
+
edit.jezik = jezik
|
519 |
+
edit.msg_content = bot.uchat.msg_content[jezik]
|
520 |
+
edit.ctxpre = bot.uchat.ctxpre
|
521 |
+
edit.save()
|
522 |
+
else:
|
523 |
+
mform.save()
|
524 |
+
return HttpResponseRedirect(reverse('params'))
|
525 |
+
else:
|
526 |
+
jezik = request.session.get('jezik','srpski')
|
527 |
+
if jezik == '': jezik='srpski'
|
528 |
+
edit_all = Param.objects.all()
|
529 |
+
for edit in edit_all:
|
530 |
+
if edit.jezik == jezik:
|
531 |
+
bot.uchat.system[jezik] = edit.system
|
532 |
+
bot.uchat.ctxpre = edit.ctxpre
|
533 |
+
bot.uchat.msg_content[jezik] = edit.msg_content
|
534 |
+
bot.uchat.min_len = edit.min_len
|
535 |
+
bot.uchat.CHUNK_SIZE = edit.CHUNK_SIZE
|
536 |
+
bot.uchat.CHUNK_OVERLAP = edit.CHUNK_OVERLAP
|
537 |
+
bot.uchat.max_results = edit.max_results
|
538 |
+
bot.uchat.EMBED_MODEL = edit.EMBED_MODEL
|
539 |
+
bot.uchat.model_id = edit.model_id
|
540 |
+
bot.uchat.min_distance = edit.min_distance
|
541 |
+
bot.uchat.max_distance = edit.max_distance
|
542 |
+
bot.uchat.max_conv = edit.max_conv
|
543 |
+
bot.uchat.temperature = edit.temperature
|
544 |
+
bot.uchat.top_p = edit.top_p
|
545 |
+
bot.uchat.max_tokens = edit.max_tokens
|
546 |
+
bot.uchat.presence_penalty = edit.presence_penalty
|
547 |
+
bot.uchat.frequency_penalty = edit.frequency_penalty
|
548 |
+
bot.uchat.DEBUG = edit.DEBUG
|
549 |
+
return render(
|
550 |
+
request,
|
551 |
+
'index_params.html',
|
552 |
+
context = {'system': bot.uchat.system[jezik],
|
553 |
+
'ctrpre': bot.uchat.ctxpre,
|
554 |
+
'msg_content': bot.uchat.msg_content[jezik],
|
555 |
+
'min_len': bot.uchat.min_len,
|
556 |
+
'CHUNK_SIZE': bot.uchat.CHUNK_SIZE,
|
557 |
+
'CHUNK_OVERLAP': bot.uchat.CHUNK_OVERLAP,
|
558 |
+
'max_results': bot.uchat.max_results,
|
559 |
+
'EMBED_MODEL': bot.uchat.EMBED_MODEL, # "all-MiniLM-L6-v2",
|
560 |
+
'model_id': bot.uchat.model_id, # model_id = "Yugo60-GPT-GGUF.Q4_K_M.gguf"
|
561 |
+
'max_conv': bot.uchat.max_conv,
|
562 |
+
'min_distance': bot.uchat.min_distance,
|
563 |
+
'max_distance': bot.uchat.max_distance,
|
564 |
+
'temperature': bot.uchat.temperature,
|
565 |
+
'max_tokens': bot.uchat.max_tokens,
|
566 |
+
'top_p': bot.uchat.top_p,
|
567 |
+
'frequency_penalty': bot.uchat.frequency_penalty,
|
568 |
+
'presence_penalty': bot.uchat.presence_penalty,
|
569 |
+
'DEBUG': bot.uchat.DEBUG,
|
570 |
+
'selected_hr': selected(jezik,'hrvatski'),
|
571 |
+
'selected_sl': selected(jezik,'slovenački'),
|
572 |
+
'selected_sr': selected(jezik,'srpski'),
|
573 |
+
'selected_mk': selected(jezik,'makedonski'),
|
574 |
+
}
|
575 |
+
)
|
576 |
+
|
577 |
+
def importPdf(request):
|
578 |
+
if request.method == "POST":
|
579 |
+
form = ImportForm(request.POST)
|
580 |
+
if form.is_valid():
|
581 |
+
path = form.cleaned_data['path']
|
582 |
+
jezik = form.cleaned_data['jezik']
|
583 |
+
request.session['jezik'] = jezik
|
584 |
+
request.session['path'] = path
|
585 |
+
l_last = bot.uchat.last
|
586 |
+
try:
|
587 |
+
bot.uchat.load_docs(path, jezik)
|
588 |
+
l_last = bot.uchat.last - l_last
|
589 |
+
request.session['answer'] = f"Importovano {l_last} delova PDF dokumenta."
|
590 |
+
except:
|
591 |
+
if bot.uchat.DEBUG: print("Došlo je do problema sa importom PDF fajla.")
|
592 |
+
request.session['answer'] = "Došlo je do problema sa importom PDF fajla."
|
593 |
+
return HttpResponseRedirect(reverse('importpdf'))
|
594 |
+
else:
|
595 |
+
jezik = request.session.get('jezik','srpski')
|
596 |
+
path = request.session.get('path','/Users/profile/...')
|
597 |
+
answer = request.session.get('answer','')
|
598 |
+
return render(
|
599 |
+
request,
|
600 |
+
'index_import.html',
|
601 |
+
context = {'path': path,
|
602 |
+
'answer': answer,
|
603 |
+
'selected_hr': selected(jezik,'hrvatski'),
|
604 |
+
'selected_sl': selected(jezik,'slovenački'),
|
605 |
+
'selected_sr': selected(jezik,'srpski'),
|
606 |
+
'selected_mk': selected(jezik,'makedonski'),
|
607 |
+
}
|
608 |
+
)
|
609 |
+
|
610 |
+
from django.views import generic
|
611 |
+
|
612 |
+
class BotView(generic.ListView):
|
613 |
+
"""View for a bot chat."""
|
614 |
+
if bot.uchat.DEBUG: print ("Test!")
|
615 |
+
model = Language
|
616 |
+
paginate_by = 5
|
617 |
+
last = bot.uchat.last
|
618 |
+
|
619 |
+
class BotViewDetail(generic.DetailView):
|
620 |
+
model = Language
|
621 |
+
|
622 |
+
##@login_required
|
623 |
+
##@permission_required('catalog.can_mark_returned', raise_exception=True)
|
624 |
+
|
templates/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
templates/base_generic.html
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
{% block title %}<title>UChat</title>{% endblock %}
|
5 |
+
<meta charset="utf-8">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
7 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
8 |
+
|
9 |
+
<!-- Add additional CSS in static file -->
|
10 |
+
{% load static %}
|
11 |
+
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
|
12 |
+
</head>
|
13 |
+
<body>
|
14 |
+
|
15 |
+
<div class="container-fluid">
|
16 |
+
|
17 |
+
<div class="row">
|
18 |
+
<div class="col-sm-2">
|
19 |
+
{% block sidebar %}
|
20 |
+
<ul class="sidebar-nav">
|
21 |
+
<li><a href="{% url 'index' %}">UChat</a></li>
|
22 |
+
<li><a href="{% url 'bot' %}">UChat editor</a></li>
|
23 |
+
<li><a href="{% url 'params' %}">Parametri</a></li>
|
24 |
+
<li><a href="{% url 'importpdf' %}">Import PDF</li>
|
25 |
+
</ul>
|
26 |
+
|
27 |
+
<ul class="sidebar-nav">
|
28 |
+
{% if user.is_authenticated %}
|
29 |
+
<li>User: {{ user.get_username }}</li>
|
30 |
+
<li><a href="{% url 'admin' %}">Admin</a></li>
|
31 |
+
<li><a href="{% url 'logout'%}?next={{request.path}}">Logout</a></li>
|
32 |
+
{% else %}
|
33 |
+
<li><a href="{% url 'login'%}?next={{request.path}}">Login</a></li>
|
34 |
+
{% endif %}
|
35 |
+
</ul>
|
36 |
+
|
37 |
+
{% if user.is_staff %}
|
38 |
+
<hr>
|
39 |
+
<ul class="sidebar-nav">
|
40 |
+
<li>Admin</li>
|
41 |
+
{% if True %}
|
42 |
+
<li><a href="{% url 'admin' %}">Admin</a></li>
|
43 |
+
{% endif %}
|
44 |
+
</ul>
|
45 |
+
{% endif %}
|
46 |
+
|
47 |
+
{% endblock %}
|
48 |
+
</div>
|
49 |
+
<div class="col-sm-10 ">
|
50 |
+
{% block content %}{% endblock %}
|
51 |
+
|
52 |
+
{% block pagination %}
|
53 |
+
{% if is_paginated %}
|
54 |
+
<div class="pagination">
|
55 |
+
<span class="page-links">
|
56 |
+
{% if page_obj.has_previous %}
|
57 |
+
<a href="{{ request.path }}?page={{ page_obj.previous_page_number }}">previous</a>
|
58 |
+
{% endif %}
|
59 |
+
<span class="page-current">
|
60 |
+
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
|
61 |
+
</span>
|
62 |
+
{% if page_obj.has_next %}
|
63 |
+
<a href="{{ request.path }}?page={{ page_obj.next_page_number }}">next</a>
|
64 |
+
{% endif %}
|
65 |
+
</span>
|
66 |
+
</div>
|
67 |
+
{% endif %}
|
68 |
+
{% endblock %}
|
69 |
+
</div>
|
70 |
+
</div>
|
71 |
+
|
72 |
+
</div>
|
73 |
+
</body>
|
74 |
+
</html>
|
templates/bot/language_detail.html
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{% extends "base_generic.html" %}
|
2 |
+
|
3 |
+
{% block content %}
|
4 |
+
|
5 |
+
<h1>Jezik: {{ language.name }}</h1>
|
6 |
+
|
7 |
+
<ul>
|
8 |
+
<li>
|
9 |
+
<p><strong>ID:</strong> {{ language.id}}</p>
|
10 |
+
</li>
|
11 |
+
<li>
|
12 |
+
<p><strong>Skraćeno:</strong> {{ language.lid }}</p>
|
13 |
+
</li>
|
14 |
+
</ul>
|
15 |
+
|
16 |
+
{% endblock %}
|
templates/bot/language_list.html
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{% extends "base_generic.html" %}
|
2 |
+
|
3 |
+
{% block content %}
|
4 |
+
|
5 |
+
<h1>Language List</h1>
|
6 |
+
|
7 |
+
<ul>
|
8 |
+
{% for language in language_list %}
|
9 |
+
<li>
|
10 |
+
<a href="{{ language.get_absolute_url }}">{{ language.name }}</a>
|
11 |
+
</li>
|
12 |
+
{% empty %}
|
13 |
+
<li>There are no languages available.</li>
|
14 |
+
{% endfor %}
|
15 |
+
</ul>
|
16 |
+
{% endblock %}
|
templates/index.html
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
{% extends "base_generic.html" %}
|
3 |
+
|
4 |
+
{% block content %}
|
5 |
+
|
6 |
+
<script type="text/javascript">
|
7 |
+
function status(element) {
|
8 |
+
document.getElementById("query").style.display = "hidden"
|
9 |
+
element.submit()
|
10 |
+
}
|
11 |
+
</script>
|
12 |
+
<h1>UChat prototip</h1>
|
13 |
+
|
14 |
+
<p>
|
15 |
+
<div style="width:800px;overflow:auto">
|
16 |
+
<pre style="white-space:pre-wrap;">
|
17 |
+
{{ reply }}
|
18 |
+
</pre>
|
19 |
+
</p>
|
20 |
+
</div>
|
21 |
+
<p>
|
22 |
+
<form onsubmit="status(this)" action="{% url 'index' %}" method="POST">
|
23 |
+
{% csrf_token %}
|
24 |
+
<label for="query">Prompt: </label>
|
25 |
+
<br>
|
26 |
+
<input type="text" id="query" name="query" maxlength="130" size="80" value="" autofocus>
|
27 |
+
<br>
|
28 |
+
<input type="submit" value="OK">
|
29 |
+
<br><br>
|
30 |
+
<label for="jezik">Jezik:</label>
|
31 |
+
<select id="jezik" name="jezik">
|
32 |
+
<option value="hrvatski" {{ selected_hr }}>hrvatski</option>
|
33 |
+
<option value="slovenački" {{ selected_sl }}>slovenački</option>
|
34 |
+
<option value="srpski" {{ selected_sr }}>srpski</option>
|
35 |
+
<option value="makedonski" {{ selected_mk }}>makedonski</option>
|
36 |
+
</select>
|
37 |
+
</form>
|
38 |
+
</p>
|
39 |
+
|
40 |
+
{% endblock %}
|
41 |
+
|
templates/index_editor.html
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{% extends "base_generic.html" %}
|
2 |
+
|
3 |
+
{% block content %}
|
4 |
+
|
5 |
+
<h1>Editor</h1>
|
6 |
+
<br>
|
7 |
+
<table width="100%">
|
8 |
+
<caption>Ukupno: {{ nr }} od {{ last }}</caption>
|
9 |
+
<thead>
|
10 |
+
<tr>
|
11 |
+
<th width="5%">id</th>
|
12 |
+
{% if id == "" %}
|
13 |
+
<th width="5%">state</th>
|
14 |
+
<th width="5%">next</th>
|
15 |
+
<th width="5%">page</th>
|
16 |
+
<th width="10%">jezik</th>
|
17 |
+
<th widht="70%">document</th>
|
18 |
+
</tr><tr>
|
19 |
+
<form action="{% url "bot"%}" method="POST">
|
20 |
+
{% csrf_token %}
|
21 |
+
<th><input type="text" maxlength=5" size="5" id="f_id" name="f_id" value="{{ f_id }}"></th>
|
22 |
+
<th><input type="text" maxlength=5" size="5" id="f_state" name="f_state" value="{{ f_state }}"></th>
|
23 |
+
<th><input type="text" maxlength=5" size="5" id="f_next" name="f_next" value="{{ f_next }}"></th>
|
24 |
+
<th><input type="text" maxlength=5" size="5" id="f_page" name="f_page" value="{{ f_page }}"></th>
|
25 |
+
<th><input type="text" maxlength=10" size="10" id="f_jezik" name="f_jezik" value="{{ f_jezik }}"></th>
|
26 |
+
<th><input type="text" maxlength=64" size="64" id="f_docu" name="f_docu" value="{{ f_docu }}"></th>
|
27 |
+
<input type="submit" value="Refresh">
|
28 |
+
</form>
|
29 |
+
{% endif %}
|
30 |
+
</tr>
|
31 |
+
</thead>
|
32 |
+
<tbody>
|
33 |
+
{% if id == "" %}
|
34 |
+
{% for row in id_docs %}
|
35 |
+
<tr>
|
36 |
+
{% for col in row %}
|
37 |
+
{% if col|slice:":2" == "id" %}
|
38 |
+
<td><a href="{% url 'editor_id' col|slice:"2:" 0 %}">{{ col }}</a></td>
|
39 |
+
{% else %}
|
40 |
+
<td width="">{{ col|truncatewords:16 }}</td>
|
41 |
+
{% endif %}
|
42 |
+
{% endfor %}
|
43 |
+
</tr>
|
44 |
+
{% endfor %}
|
45 |
+
{% else %}
|
46 |
+
<tr><td>{{ id }}</td><td></td></tr>
|
47 |
+
{% endif %}
|
48 |
+
</tbody>
|
49 |
+
</table>
|
50 |
+
<br>
|
51 |
+
{% if id != "" %}
|
52 |
+
<form action='{% url 'editor_id' id 0 %}' method="POST">
|
53 |
+
{% csrf_token %}
|
54 |
+
<table>
|
55 |
+
<input type="hidden" id="id" name="id" value="id{{ id }}">
|
56 |
+
<tr><td><label for="state">state:</label></td><td><input type="text" id="state" name="state" value="{{ state }}"></input></td></tr>
|
57 |
+
<tr><td><label for="next">next:</label></td><td><input type="text" id="next" name="next" value="{{ next }}"></input></td></tr>
|
58 |
+
<tr><td><label for="page">page:</label></td><td><input type="text" id="page" name="page" value="{{ page }}"></input></td></tr>
|
59 |
+
<tr><td><label for="used">used:</label></td><td><input type="text" id="used" name="used" value="{{ used }}"></input></td></tr>
|
60 |
+
<tr><td><label for="docu">document:</label></td><td><textarea id="docu" name="docu" cols="80" rows="10">{{ docu }}</textarea></td></tr>
|
61 |
+
<tr><td><label for="source">source:</label></td><td><input type="text" id="source" name="source" value="{{ source }}"></input></td></tr>
|
62 |
+
<tr><td></td><td> <select id="jezik" name="jezik">
|
63 |
+
<option value="hrvatski" {{ selected_hr }}>hrvatski</option>
|
64 |
+
<option value="slovenački" {{ selected_sl }}>slovenački</option>
|
65 |
+
<option value="srpski" {{ selected_sr }}>srpski</option>
|
66 |
+
<option value="makedonski" {{ selected_mk }}>makedonski</option>
|
67 |
+
</select></td></tr>
|
68 |
+
</table>
|
69 |
+
<br>
|
70 |
+
<div><input type="submit" value="Update" /></div>
|
71 |
+
<div><input type="submit" value="Create" formaction="{% url 'editor_id' id 1 %}" /></div>
|
72 |
+
<div><input type="submit" value="Delete" formaction="{% url 'editor_id' id 2 %}" /></div>
|
73 |
+
<br>
|
74 |
+
</form>
|
75 |
+
{% endif %}
|
76 |
+
{% endblock %}
|
templates/index_import.html
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
{% extends "base_generic.html" %}
|
3 |
+
|
4 |
+
{% block content %}
|
5 |
+
|
6 |
+
<h1>PDF import</h1>
|
7 |
+
<p/>
|
8 |
+
{{ answer }}
|
9 |
+
<p/>
|
10 |
+
<form action="{% url 'importpdf' %}" method="POST">
|
11 |
+
{% csrf_token %}
|
12 |
+
<label for="path">Path: </label>
|
13 |
+
<br>
|
14 |
+
<input type="text" id="path" name="path" maxlength="196" size="80" value="{{ path }}" autofocus>
|
15 |
+
<br>
|
16 |
+
<input type="submit" value="OK">
|
17 |
+
<p/>
|
18 |
+
<select id="jezik" name="jezik">
|
19 |
+
<option value="hrvatski" {{ selected_hr }}>hrvatski</option>
|
20 |
+
<option value="slovenački" {{ selected_sl }}>slovenački</option>
|
21 |
+
<option value="srpski" {{ selected_sr }}>srpski</option>
|
22 |
+
<option value="makedonski" {{ selected_mk }}>makedonski</option>
|
23 |
+
</select>
|
24 |
+
<
|
25 |
+
</form>
|
26 |
+
<p/>
|
27 |
+
|
28 |
+
{% endblock %}
|
29 |
+
|
templates/index_params.html
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
{% extends "base_generic.html" %}
|
3 |
+
|
4 |
+
{% block content %}
|
5 |
+
|
6 |
+
<script type="text/javascript">
|
7 |
+
function status(element) {
|
8 |
+
element.style.display = "hidden"
|
9 |
+
element.submit()
|
10 |
+
}
|
11 |
+
</script>
|
12 |
+
<h1>UChat prototip</h1>
|
13 |
+
<p><p>
|
14 |
+
<form onsubmit="status(this); return true;" action="{% url 'params-refresh' %}" method="POST" name="ParamForm" id="ParamForm">
|
15 |
+
{% csrf_token %}
|
16 |
+
<table border="0">
|
17 |
+
<tr><td>
|
18 |
+
<label for="CHUNK_SIZE">CHUNK_SIZE: </label></td><td>
|
19 |
+
<input type="text" id="CHUNK_SIZE" name="CHUNK_SIZE" maxlength="8" size="8" value="{{ CHUNK_SIZE }}">
|
20 |
+
</td></tr>
|
21 |
+
<tr><td>
|
22 |
+
<label for="CHUNK_OVERLAP">CHUNK_OVERLAP: </label></td><td>
|
23 |
+
<input type="text" id="CHUNK_OVERLAP" name="CHUNK_OVERLAP" maxlength="8" size="8" value="{{ CHUNK_OVERLAP }}">
|
24 |
+
</td></tr>
|
25 |
+
<tr><td>
|
26 |
+
<label for="min_distance">min_distance: </label></td><td>
|
27 |
+
<input type="text" id="min_distance" name="min_distance" maxlength="8" size="8" value="{{ min_distance }}">
|
28 |
+
</ttd></tr>
|
29 |
+
<tr><td>
|
30 |
+
<label for="max_distance">max_distance: </label></td><td>
|
31 |
+
<input type="text" id="max_distance" name="max_distance" maxlength="8" size="8" value="{{ max_distance }}">
|
32 |
+
</td></tr>
|
33 |
+
<tr><td>
|
34 |
+
<label for="max_results">max_results: </label></td><td>
|
35 |
+
<input type="text" id="max_results" name="max_results" maxlength="8" size="8" value="{{ max_results }}">
|
36 |
+
</td></tr>
|
37 |
+
<tr><td>
|
38 |
+
<label for="max_conv">max_conv: </label></td><td>
|
39 |
+
<input type="text" id="max_conv" name="max_conv" maxlength="8" size="8" value="{{ max_conv }}">
|
40 |
+
</td></tr>
|
41 |
+
<tr><td>
|
42 |
+
<label for="min_len">min_len: </label></td><td>
|
43 |
+
<input type="text" id="min_len" name="min_len" maxlength="8" size="8" value="{{ min_len }}">
|
44 |
+
</td></tr>
|
45 |
+
<tr><td>
|
46 |
+
<label for="temperature">temperature: </label></td><td>
|
47 |
+
<input type="text" id="temperature" name="temperature" maxlength="8" size="8" value="{{ temperature }}">
|
48 |
+
</td></tr>
|
49 |
+
<tr><td>
|
50 |
+
<label for="top_p">top_p: </label></td><td>
|
51 |
+
<input type="text" id="top_p" name="top_p" maxlength="8" size="8" value="{{ top_p }}">
|
52 |
+
</td></tr>
|
53 |
+
<tr><td>
|
54 |
+
<label for="frequency_penalty">frequency_penalty: </label></td><td>
|
55 |
+
<input type="text" id="frequency_penalty" name="frequency_penalty" maxlength="8" size="8" value="{{ frequency_penalty }}">
|
56 |
+
</td></tr>
|
57 |
+
<tr><td>
|
58 |
+
<label for="presence_penalty">presence_penalty: </label></td><td>
|
59 |
+
<input type="text" id="presence_penalty" name="presence_penalty" maxlength="8" size="8" value="{{ presence_penalty }}">
|
60 |
+
</td></tr>
|
61 |
+
<tr><td>
|
62 |
+
<label for="max_tokens">max_tokens: </label></td><td>
|
63 |
+
<input type="text" id="max_tokens" name="max_tokens" maxlength="8" size="8" value="{{ max_tokens }}">
|
64 |
+
</td></tr>
|
65 |
+
<tr><td>
|
66 |
+
<label for="DEBUG">DEBUG: </label></td><td>
|
67 |
+
<input type="text" id="DEBUG" name="DEBUG" maxlength="8" size="8" value="{{ DEBUG }}">
|
68 |
+
</td></tr>
|
69 |
+
<tr><td>
|
70 |
+
<label for="ctxpre">ctxpre: </label></td><td>
|
71 |
+
<input type="text" id="ctxpre" name="ctxpre" maxlength="8" size="8" value="{{ ctxpre }}">
|
72 |
+
</td></tr>
|
73 |
+
<tr><td>
|
74 |
+
<label for="EMBED_MODEL">EMBED_MODEL: </label></td><td>
|
75 |
+
<input type="text" id="EMBED_MODEL" name="EMBED_MODEL" maxlength="80" size="80" value="{{ EMBED_MODEL }}">
|
76 |
+
</td></tr>
|
77 |
+
<tr><td>
|
78 |
+
<label for="model_id">model_id: </label></td><td>
|
79 |
+
<input type="text" id="model_id" name="model_id" maxlength="80" size="80" value="{{ model_id }}">
|
80 |
+
</td></tr>
|
81 |
+
<tr><td>
|
82 |
+
<label for="msg_content">msg_content: (*)</label></td><td>
|
83 |
+
<input type="text" id="msg_content" name="msg_content" maxlength="80" size="80" value="{{ msg_content }}">
|
84 |
+
</td></tr>
|
85 |
+
<tr><td colspan="1">
|
86 |
+
<label for="system">system: (*) </label><br></td>
|
87 |
+
<td>
|
88 |
+
<select id="jezik" name="jezik" onchange='this.form.submit();'>
|
89 |
+
<option value="hrvatski" {{ selected_hr }}>hrvatski</option>
|
90 |
+
<option value="slovenački" {{ selected_sl }}>slovenački</option>
|
91 |
+
<option value="srpski" {{ selected_sr }}>srpski</option>
|
92 |
+
<option value="makedonski" {{ selected_mk }}>makedonski</option>
|
93 |
+
</select>
|
94 |
+
(*)
|
95 |
+
</td></tr>
|
96 |
+
<tr><td></td><td>
|
97 |
+
<textarea id="system" name="system" rows="10" cols="80">{{ system }}</textarea>
|
98 |
+
</td></tr>
|
99 |
+
</table>
|
100 |
+
<input type="submit" value="Refresh">
|
101 |
+
<input type="submit" value="Set" formaction="{% url 'params' %}">
|
102 |
+
|
103 |
+
<input type="submit" value="Reset" formaction="{% url 'reset' %}">
|
104 |
+
</form>
|
105 |
+
|
106 |
+
{% endblock %}
|
107 |
+
|
templates/registration/logged_out.html
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{% extends "base_generic.html" %}
|
2 |
+
|
3 |
+
{% block content %}
|
4 |
+
<p>Logged out!</p>
|
5 |
+
|
6 |
+
<a href="{% url 'login'%}">Click here to login again.</a>
|
7 |
+
{% endblock %}
|
templates/registration/login.html
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{% extends "base_generic.html" %}
|
2 |
+
|
3 |
+
{% block content %}
|
4 |
+
|
5 |
+
{% if form.errors %}
|
6 |
+
<p>Your username and password didn't match. Please try again.</p>
|
7 |
+
{% endif %}
|
8 |
+
|
9 |
+
{% if next %}
|
10 |
+
{% if user.is_authenticated %}
|
11 |
+
<p>Your account doesn't have access to this page. To proceed,
|
12 |
+
please login with an account that has access.</p>
|
13 |
+
{% else %}
|
14 |
+
<p>Please login to see this page.</p>
|
15 |
+
{% endif %}
|
16 |
+
{% endif %}
|
17 |
+
|
18 |
+
<form method="post" action="{% url 'login' %}">
|
19 |
+
{% csrf_token %}
|
20 |
+
<table>
|
21 |
+
<tr>
|
22 |
+
<td>{{ form.username.label_tag }}</td>
|
23 |
+
<td>{{ form.username }}</td>
|
24 |
+
</tr>
|
25 |
+
<tr>
|
26 |
+
<td>{{ form.password.label_tag }}</td>
|
27 |
+
<td>{{ form.password }}</td>
|
28 |
+
</tr>
|
29 |
+
</table>
|
30 |
+
|
31 |
+
<input type="submit" value="login">
|
32 |
+
<input type="hidden" name="next" value="{{ next }}">
|
33 |
+
</form>
|
34 |
+
|
35 |
+
{# Assumes you setup the password_reset view in your URLconf #}
|
36 |
+
<p><a href="{% url 'password_reset' %}">Lost password?</a></p>
|
37 |
+
|
38 |
+
{% endblock %}
|