pygpt-net 2.4.36.post1__py3-none-any.whl → 2.4.37__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- CHANGELOG.md +9 -1
- README.md +37 -9
- pygpt_net/CHANGELOG.txt +9 -1
- pygpt_net/__init__.py +3 -3
- pygpt_net/controller/chat/attachment.py +7 -39
- pygpt_net/core/attachments/context.py +132 -42
- pygpt_net/core/bridge/worker.py +16 -2
- pygpt_net/core/events/event.py +2 -1
- pygpt_net/core/idx/chat.py +22 -24
- pygpt_net/data/config/config.json +7 -5
- pygpt_net/data/config/models.json +3 -3
- pygpt_net/data/config/modes.json +3 -3
- pygpt_net/data/config/settings.json +26 -0
- pygpt_net/data/locale/locale.de.ini +7 -3
- pygpt_net/data/locale/locale.en.ini +13 -9
- pygpt_net/data/locale/locale.es.ini +7 -3
- pygpt_net/data/locale/locale.fr.ini +7 -3
- pygpt_net/data/locale/locale.it.ini +7 -3
- pygpt_net/data/locale/locale.pl.ini +8 -4
- pygpt_net/data/locale/locale.uk.ini +7 -3
- pygpt_net/data/locale/locale.zh.ini +8 -4
- pygpt_net/plugin/idx_llama_index/__init__.py +2 -2
- pygpt_net/plugin/real_time/__init__.py +2 -2
- pygpt_net/provider/core/config/patch.py +12 -1
- {pygpt_net-2.4.36.post1.dist-info → pygpt_net-2.4.37.dist-info}/METADATA +38 -10
- {pygpt_net-2.4.36.post1.dist-info → pygpt_net-2.4.37.dist-info}/RECORD +29 -29
- {pygpt_net-2.4.36.post1.dist-info → pygpt_net-2.4.37.dist-info}/LICENSE +0 -0
- {pygpt_net-2.4.36.post1.dist-info → pygpt_net-2.4.37.dist-info}/WHEEL +0 -0
- {pygpt_net-2.4.36.post1.dist-info → pygpt_net-2.4.37.dist-info}/entry_points.txt +0 -0
CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 2.4.37 (2024-11-30)
|
4
|
+
|
5
|
+
- The `Query only` mode in `Uploaded` tab has been renamed to `RAG`.
|
6
|
+
- New options have been added under `Settings -> Files and Attachments`:
|
7
|
+
- `Use history in RAG query`: When enabled, the content of the entire conversation will be used when preparing a query if the mode is set to RAG or Summary.
|
8
|
+
- `RAG limit`: This option is applicable only if 'Use history in RAG query' is enabled. It specifies the limit on how many recent entries in the conversation will be used when generating a query for RAG. A value of 0 indicates no limit.
|
9
|
+
- Cache: dynamic parts of the system prompt (from plugins) have been moved to the very end of the prompt stack to enable the use of prompt cache mechanisms in OpenAI.
|
10
|
+
|
3
11
|
## 2.4.36 (2024-11-28)
|
4
12
|
|
5
13
|
- Added a new command-line argument: --workdir="/path/to/workdir" to explicitly set the current working directory.
|
@@ -33,7 +41,7 @@
|
|
33
41
|
|
34
42
|
- Added an option checkbox `Auto-index on upload` in the `Attachments` tab:
|
35
43
|
|
36
|
-
**Tip:** To use the `
|
44
|
+
**Tip:** To use the `RAG` mode, the file must be indexed in the vector database. This occurs automatically at the time of upload if the `Auto-index on upload` option in the `Attachments` tab is enabled. When uploading large files, such indexing might take a while - therefore, if you are using the `Full context` option, which does not use the index, you can disable the `Auto-index` option to speed up the upload of the attachment. In this case, it will only be indexed when the `RAG` option is called for the first time, and until then, attachment will be available in the form of `Full context` and `Summary`.
|
37
45
|
|
38
46
|
- Added context menu options in `Uploaded attachments` tab: `Open`, `Open Source directory` and `Open Storage directory`.
|
39
47
|
|
README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://snapcraft.io/pygpt)
|
4
4
|
|
5
|
-
Release: **2.4.
|
5
|
+
Release: **2.4.37** | build: **2024.11.30** | Python: **>=3.10, <3.12**
|
6
6
|
|
7
7
|
> Official website: https://pygpt.net | Documentation: https://pygpt.readthedocs.io
|
8
8
|
>
|
@@ -603,11 +603,11 @@ Built-in file loaders:
|
|
603
603
|
- Webpages (crawling any webpage content)
|
604
604
|
- YouTube (transcriptions)
|
605
605
|
|
606
|
-
You can configure data loaders in `Settings / LlamaIndex / Data Loaders` by providing list of keyword arguments for specified loaders.
|
606
|
+
You can configure data loaders in `Settings / Indexes (LlamaIndex) / Data Loaders` by providing list of keyword arguments for specified loaders.
|
607
607
|
You can also develop and provide your own custom loader and register it within the application.
|
608
608
|
|
609
609
|
LlamaIndex is also integrated with context database - you can use data from database (your context history) as additional context in discussion.
|
610
|
-
Options for indexing existing context history or enabling real-time indexing new ones (from database) are available in `Settings / LlamaIndex` section.
|
610
|
+
Options for indexing existing context history or enabling real-time indexing new ones (from database) are available in `Settings / Indexes (LlamaIndex)` section.
|
611
611
|
|
612
612
|
**WARNING:** remember that when indexing content, API calls to the embedding model are used. Each indexing consumes additional tokens. Always control the number of tokens used on the OpenAI page.
|
613
613
|
|
@@ -669,7 +669,7 @@ You can set the limit of steps in such a loop by going to `Settings -> Agents an
|
|
669
669
|
|
670
670
|
You can change the prompt used for evaluating the response in `Settings -> Prompts -> Agent: evaluation prompt in loop`. Here, you can adjust it to suit your needs, for example, by defining more or less critical feedback for the responses received.
|
671
671
|
|
672
|
-
## Agent (
|
672
|
+
## Agent (Autonomous)
|
673
673
|
|
674
674
|
This is an older version of the Agent mode, still available as legacy. However, it is recommended to use the newer mode: `Agent (LlamaIndex)`.
|
675
675
|
|
@@ -817,11 +817,13 @@ The content from the uploaded attachments will be used in the current conversati
|
|
817
817
|
|
818
818
|
- `Full context`: Provides best results. This mode attaches the entire content of the read file to the user's prompt. This process happens in the background and may require a large number of tokens if you uploaded extensive content.
|
819
819
|
|
820
|
-
- `
|
820
|
+
- `RAG`: The indexed attachment will only be queried in real-time using LlamaIndex. This operation does not require any additional tokens, but it may not provide access to the full content of the file 1:1.
|
821
821
|
|
822
822
|
- `Summary`: When queried, an additional query will be generated in the background and executed by a separate model to summarize the content of the attachment and return the required information to the main model. You can change the model used for summarization in the settings under the `Files and attachments` section.
|
823
823
|
|
824
|
-
|
824
|
+
In the `RAG` and `Summary` mode, you can enable an additional setting by going to `Settings -> Files and attachments -> Use history in RAG query`. This allows for better preparation of queries for RAG. When this option is turned on, the entire conversation context is considered, rather than just the user's last query. This allows for better searching of the index for additional context. In the `RAG limit` option, you can set a limit on how many recent entries in a discussion should be considered (`0 = no limit, default: 3`).
|
825
|
+
|
826
|
+
**Important**: When using `Full context` mode, the entire content of the file is included in the prompt, which can result in high token usage each time. If you want to reduce the number of tokens used, instead use the `RAG` option, which will only query the indexed attachment in the vector database to provide additional context.
|
825
827
|
|
826
828
|
**Images as Additional Context**
|
827
829
|
|
@@ -829,7 +831,7 @@ Files such as jpg, png, and similar images are a special case. By default, image
|
|
829
831
|
|
830
832
|
**Uploading larger files and auto-index**
|
831
833
|
|
832
|
-
To use the `
|
834
|
+
To use the `RAG` mode, the file must be indexed in the vector database. This occurs automatically at the time of upload if the `Auto-index on upload` option in the `Attachments` tab is enabled. When uploading large files, such indexing might take a while - therefore, if you are using the `Full context` option, which does not use the index, you can disable the `Auto-index` option to speed up the upload of the attachment. In this case, it will only be indexed when the `RAG` option is called for the first time, and until then, attachment will be available in the form of `Full context` and `Summary`.
|
833
835
|
|
834
836
|
## Downloading files
|
835
837
|
|
@@ -2710,6 +2712,16 @@ Config -> Settings...
|
|
2710
2712
|
|
2711
2713
|
- `Directory for file downloads`: Subdirectory for downloaded files, e.g. in Assistants mode, inside "data". Default: "download"
|
2712
2714
|
|
2715
|
+
- `Verbose mode`: Enabled verbose mode when using attachment as additional context.
|
2716
|
+
|
2717
|
+
- `Model for querying index`: Model to use for preparing query and querying the index when the RAG option is selected.
|
2718
|
+
|
2719
|
+
- `Model for attachment content summary`: Model to use when generating a summary for the content of a file when the Summary option is selected.
|
2720
|
+
|
2721
|
+
- `Use history in RAG query`: When enabled, the content of the entire conversation will be used when preparing a query if mode is RAG or Summary.
|
2722
|
+
|
2723
|
+
- `RAG limit`: Only if the option `Use history in RAG query` is enabled. Specify the limit of how many recent entries in the conversation will be used when generating a query for RAG. 0 = no limit.
|
2724
|
+
|
2713
2725
|
**Context**
|
2714
2726
|
|
2715
2727
|
- `Context Threshold`: Sets the number of tokens reserved for the model to respond to the next prompt.
|
@@ -3247,7 +3259,7 @@ If you want to only query index (without chat) you can enable `Query index only
|
|
3247
3259
|
|
3248
3260
|
You can create a custom vector store provider or data loader for your data and develop a custom launcher for the application.
|
3249
3261
|
|
3250
|
-
See the section `Extending PyGPT / Adding custom Vector Store provider` for more details.
|
3262
|
+
See the section `Extending PyGPT / Adding a custom Vector Store provider` for more details.
|
3251
3263
|
|
3252
3264
|
# Updates
|
3253
3265
|
|
@@ -3545,6 +3557,8 @@ Syntax: `event name` - triggered on, `event data` *(data type)*:
|
|
3545
3557
|
|
3546
3558
|
- `AI_NAME` - when preparing an AI name, `data['value']` *(string, name of the AI assistant)*
|
3547
3559
|
|
3560
|
+
- `AGENT_PROMPT` - on agent prompt in eval mode, `data['value']` *(string, prompt)*
|
3561
|
+
|
3548
3562
|
- `AUDIO_INPUT_RECORD_START` - start audio input recording
|
3549
3563
|
|
3550
3564
|
- `AUDIO_INPUT_RECORD_STOP` - stop audio input recording
|
@@ -3603,10 +3617,16 @@ Syntax: `event name` - triggered on, `event data` *(data type)*:
|
|
3603
3617
|
|
3604
3618
|
- `POST_PROMPT` - after preparing a system prompt, `data['value']` *(string, system prompt)*
|
3605
3619
|
|
3620
|
+
- `POST_PROMPT_ASYNC` - after preparing a system prompt, just before request in async thread, `data['value']` *(string, system prompt)*
|
3621
|
+
|
3622
|
+
- `POST_PROMPT_END` - after preparing a system prompt, just before request in async thread, at the very end `data['value']` *(string, system prompt)*
|
3623
|
+
|
3606
3624
|
- `PRE_PROMPT` - before preparing a system prompt, `data['value']` *(string, system prompt)*
|
3607
3625
|
|
3608
3626
|
- `SYSTEM_PROMPT` - when preparing a system prompt, `data['value']` *(string, system prompt)*
|
3609
3627
|
|
3628
|
+
- `TOOL_OUTPUT_RENDER` - when rendering extra content from tools from plugins, `data['content']` *(string, content)*
|
3629
|
+
|
3610
3630
|
- `UI_ATTACHMENTS` - when the attachment upload elements are rendered, `data['value']` *(bool, show True/False)*
|
3611
3631
|
|
3612
3632
|
- `UI_VISION` - when the vision elements are rendered, `data['value']` *(bool, show True/False)*
|
@@ -3845,6 +3865,14 @@ may consume additional tokens that are not displayed in the main window.
|
|
3845
3865
|
|
3846
3866
|
## Recent changes:
|
3847
3867
|
|
3868
|
+
**2.4.37 (2024-11-30)**
|
3869
|
+
|
3870
|
+
- The `Query only` mode in `Uploaded` tab has been renamed to `RAG`.
|
3871
|
+
- New options have been added under `Settings -> Files and Attachments`:
|
3872
|
+
- `Use history in RAG query`: When enabled, the content of the entire conversation will be used when preparing a query if the mode is set to RAG or Summary.
|
3873
|
+
- `RAG limit`: This option is applicable only if 'Use history in RAG query' is enabled. It specifies the limit on how many recent entries in the conversation will be used when generating a query for RAG. A value of 0 indicates no limit.
|
3874
|
+
- Cache: dynamic parts of the system prompt (from plugins) have been moved to the very end of the prompt stack to enable the use of prompt cache mechanisms in OpenAI.
|
3875
|
+
|
3848
3876
|
**2.4.36 (2024-11-28)**
|
3849
3877
|
|
3850
3878
|
- Added a new command-line argument: --workdir="/path/to/workdir" to explicitly set the current working directory.
|
@@ -3878,7 +3906,7 @@ may consume additional tokens that are not displayed in the main window.
|
|
3878
3906
|
|
3879
3907
|
- Added an option checkbox `Auto-index on upload` in the `Attachments` tab:
|
3880
3908
|
|
3881
|
-
**Tip:** To use the `
|
3909
|
+
**Tip:** To use the `RAG` mode, the file must be indexed in the vector database. This occurs automatically at the time of upload if the `Auto-index on upload` option in the `Attachments` tab is enabled. When uploading large files, such indexing might take a while - therefore, if you are using the `Full context` option, which does not use the index, you can disable the `Auto-index` option to speed up the upload of the attachment. In this case, it will only be indexed when the `RAG` option is called for the first time, and until then, attachment will be available in the form of `Full context` and `Summary`.
|
3882
3910
|
|
3883
3911
|
- Added context menu options in `Uploaded attachments` tab: `Open`, `Open Source directory` and `Open Storage directory`.
|
3884
3912
|
|
pygpt_net/CHANGELOG.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
2.4.37 (2024-11-30)
|
2
|
+
|
3
|
+
- The `Query only` mode in `Uploaded` tab has been renamed to `RAG`.
|
4
|
+
- New options have been added under `Settings -> Files and Attachments`:
|
5
|
+
- `Use history in RAG query`: When enabled, the content of the entire conversation will be used when preparing a query if the mode is set to RAG or Summary.
|
6
|
+
- `RAG limit`: This option is applicable only if 'Use history in RAG query' is enabled. It specifies the limit on how many recent entries in the conversation will be used when generating a query for RAG. A value of 0 indicates no limit.
|
7
|
+
- Cache: dynamic parts of the system prompt (from plugins) have been moved to the very end of the prompt stack to enable the use of prompt cache mechanisms in OpenAI.
|
8
|
+
|
1
9
|
2.4.36 (2024-11-28)
|
2
10
|
|
3
11
|
- Added a new command-line argument: --workdir="/path/to/workdir" to explicitly set the current working directory.
|
@@ -31,7 +39,7 @@
|
|
31
39
|
|
32
40
|
- Added an option checkbox `Auto-index on upload` in the `Attachments` tab:
|
33
41
|
|
34
|
-
Tip: To use the `
|
42
|
+
Tip: To use the `RAG` mode, the file must be indexed in the vector database. This occurs automatically at the time of upload if the `Auto-index on upload` option in the `Attachments` tab is enabled. When uploading large files, such indexing might take a while - therefore, if you are using the `Full context` option, which does not use the index, you can disable the `Auto-index` option to speed up the upload of the attachment. In this case, it will only be indexed when the `RAG` option is called for the first time, and until then, attachment will be available in the form of `Full context` and `Summary`.
|
35
43
|
|
36
44
|
- Added context menu options in `Uploaded attachments` tab: `Open`, `Open Source directory` and `Open Storage directory`.
|
37
45
|
|
pygpt_net/__init__.py
CHANGED
@@ -6,15 +6,15 @@
|
|
6
6
|
# GitHub: https://github.com/szczyglis-dev/py-gpt #
|
7
7
|
# MIT License #
|
8
8
|
# Created By : Marcin Szczygliński #
|
9
|
-
# Updated Date: 2024.11.
|
9
|
+
# Updated Date: 2024.11.30 01:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
__author__ = "Marcin Szczygliński"
|
13
13
|
__copyright__ = "Copyright 2024, Marcin Szczygliński"
|
14
14
|
__credits__ = ["Marcin Szczygliński"]
|
15
15
|
__license__ = "MIT"
|
16
|
-
__version__ = "2.4.
|
17
|
-
__build__ = "2024.11.
|
16
|
+
__version__ = "2.4.37"
|
17
|
+
__build__ = "2024.11.30"
|
18
18
|
__maintainer__ = "Marcin Szczygliński"
|
19
19
|
__github__ = "https://github.com/szczyglis-dev/py-gpt"
|
20
20
|
__website__ = "https://pygpt.net"
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# GitHub: https://github.com/szczyglis-dev/py-gpt #
|
7
7
|
# MIT License #
|
8
8
|
# Created By : Marcin Szczygliński #
|
9
|
-
# Updated Date: 2024.11.
|
9
|
+
# Updated Date: 2024.11.29 23:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
import os
|
@@ -261,26 +261,22 @@ class Attachment(QObject):
|
|
261
261
|
"""
|
262
262
|
return self.mode
|
263
263
|
|
264
|
-
def get_context(self, ctx: CtxItem) -> str:
|
264
|
+
def get_context(self, ctx: CtxItem, history: list) -> str:
|
265
265
|
"""
|
266
266
|
Get additional context for attachment
|
267
267
|
|
268
268
|
:param ctx: CtxItem instance
|
269
|
+
:param history Context items (history)
|
269
270
|
:return: Additional context
|
270
271
|
"""
|
271
|
-
content = ""
|
272
|
-
meta = ctx.meta
|
273
272
|
if self.mode != self.MODE_DISABLED:
|
274
273
|
if self.is_verbose():
|
275
274
|
print("\nPreparing additional context...\nContext Mode: {}".format(self.mode))
|
276
275
|
|
277
|
-
self.window.core.attachments.context.reset()
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
content = self.get_query_context(meta, str(ctx.input))
|
282
|
-
elif self.mode == self.MODE_QUERY_CONTEXT_SUMMARY:
|
283
|
-
content = self.get_context_summary(ctx)
|
276
|
+
self.window.core.attachments.context.reset() # reset used files and urls
|
277
|
+
|
278
|
+
# get additional context from attachments
|
279
|
+
content = self.window.core.attachments.context.get_context(self.mode, ctx, history)
|
284
280
|
|
285
281
|
# append used files and urls to context
|
286
282
|
files = self.window.core.attachments.context.get_used_files()
|
@@ -296,34 +292,6 @@ class Attachment(QObject):
|
|
296
292
|
return "====================================\nADDITIONAL CONTEXT FROM ATTACHMENT(s): {}".format(content)
|
297
293
|
return ""
|
298
294
|
|
299
|
-
def get_full_context(self, ctx: CtxItem) -> str:
|
300
|
-
"""
|
301
|
-
Get full context for attachment
|
302
|
-
|
303
|
-
:param ctx: CtxItem instance
|
304
|
-
:return: Full context
|
305
|
-
"""
|
306
|
-
return self.window.core.attachments.context.get_context_text(ctx, filename=True)
|
307
|
-
|
308
|
-
def get_query_context(self, meta: CtxMeta, query: str) -> str:
|
309
|
-
"""
|
310
|
-
Get query context for attachment
|
311
|
-
|
312
|
-
:param meta: CtxMeta instance
|
313
|
-
:param query: Query string
|
314
|
-
:return: Query context
|
315
|
-
"""
|
316
|
-
return self.window.core.attachments.context.query_context(meta, query)
|
317
|
-
|
318
|
-
def get_context_summary(self, ctx: CtxItem) -> str:
|
319
|
-
"""
|
320
|
-
Get context summary
|
321
|
-
|
322
|
-
:param ctx: CtxItem instance
|
323
|
-
:return: Context summary
|
324
|
-
"""
|
325
|
-
return self.window.core.attachments.context.summary_context(ctx, ctx.input)
|
326
|
-
|
327
295
|
def get_uploaded_attachments(self, meta: CtxMeta) -> list:
|
328
296
|
"""
|
329
297
|
Get uploaded attachments for meta
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# GitHub: https://github.com/szczyglis-dev/py-gpt #
|
7
7
|
# MIT License #
|
8
8
|
# Created By : Marcin Szczygliński #
|
9
|
-
# Updated Date: 2024.11.
|
9
|
+
# Updated Date: 2024.11.29 23:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
import copy
|
@@ -40,7 +40,7 @@ class Context:
|
|
40
40
|
Summarize the text below by extracting the most important information,
|
41
41
|
especially those that may help answer the question:
|
42
42
|
|
43
|
-
`{query}
|
43
|
+
`{query}`
|
44
44
|
|
45
45
|
If the answer to the question is not in the text to summarize,
|
46
46
|
simply return a summary of the entire content.
|
@@ -59,25 +59,49 @@ class Context:
|
|
59
59
|
|
60
60
|
`{content}`
|
61
61
|
"""
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
62
|
+
self.rag_prompt = """
|
63
|
+
Prepare a question for the RAG engine (vector database) asking for additional context that can help obtain
|
64
|
+
extra information necessary to answer the user's question. The query should be brief and to the point,
|
65
|
+
so as to be processed as effectively as possible by the RAG engine. Below is the entire conversation
|
66
|
+
of the user with the AI assistant, and at the end the current user's question, for which you need to
|
67
|
+
prepare DIRECT query for the RAG engine for additional context, taking into account the content of the entire
|
68
|
+
discussion and its context. In your response, return only the DIRECT query for additional context,
|
69
|
+
do not return anything else besides it. The response should not contain any phrases other than the query itself:
|
70
|
+
|
71
|
+
# Good RAG query example:
|
72
|
+
|
73
|
+
`What is the capital of France?`
|
74
|
+
|
75
|
+
# Bad RAG query example:
|
76
|
+
|
77
|
+
`Can you tell me the capital of France?`
|
78
|
+
|
79
|
+
# Full conversation:
|
80
|
+
|
81
|
+
`{history}`
|
82
|
+
|
83
|
+
# User question:
|
84
|
+
|
85
|
+
`{query}`
|
86
|
+
"""
|
87
|
+
|
88
|
+
def get_context(self, mode: str, ctx: CtxItem, history: list) -> str:
|
89
|
+
"""
|
90
|
+
Get context for mode
|
91
|
+
|
92
|
+
:param mode: Context mode
|
93
|
+
:param ctx: CtxItem instance
|
94
|
+
:param history: history
|
95
|
+
:return: context
|
78
96
|
"""
|
79
|
-
|
80
|
-
|
97
|
+
content = ""
|
98
|
+
if mode == self.window.controller.chat.attachment.MODE_FULL_CONTEXT:
|
99
|
+
content = self.get_context_text(ctx, filename=True)
|
100
|
+
elif mode == self.window.controller.chat.attachment.MODE_QUERY_CONTEXT:
|
101
|
+
content = self.query_context(ctx, history)
|
102
|
+
elif mode == self.window.controller.chat.attachment.MODE_QUERY_CONTEXT_SUMMARY:
|
103
|
+
content = self.summary_context(ctx, history)
|
104
|
+
return content
|
81
105
|
|
82
106
|
def get_context_text(self, ctx: CtxItem, filename: bool = False) -> str:
|
83
107
|
"""
|
@@ -126,15 +150,17 @@ class Context:
|
|
126
150
|
self.last_used_context = context
|
127
151
|
return context
|
128
152
|
|
129
|
-
def query_context(self,
|
153
|
+
def query_context(self, ctx: CtxItem, history: list) -> str:
|
130
154
|
"""
|
131
155
|
Query the index for context
|
132
156
|
|
133
|
-
:param
|
134
|
-
:param
|
157
|
+
:param ctx: CtxItem instance
|
158
|
+
:param history: history
|
135
159
|
:return: query result
|
136
160
|
"""
|
161
|
+
meta = ctx.meta
|
137
162
|
meta_path = self.get_dir(meta)
|
163
|
+
query = str(ctx.input)
|
138
164
|
if not os.path.exists(meta_path) or not os.path.isdir(meta_path):
|
139
165
|
return ""
|
140
166
|
idx_path = os.path.join(self.get_dir(meta), self.dir_index)
|
@@ -162,8 +188,21 @@ class Context:
|
|
162
188
|
self.window.core.ctx.replace(meta)
|
163
189
|
self.window.core.ctx.save(meta.id)
|
164
190
|
|
191
|
+
history_data = self.prepare_context_history(history)
|
165
192
|
model, model_item = self.get_selected_model("query")
|
166
|
-
|
193
|
+
|
194
|
+
verbose = False
|
195
|
+
if self.is_verbose():
|
196
|
+
verbose = True
|
197
|
+
print("Attachments: using query model: {}".format(model))
|
198
|
+
|
199
|
+
result = self.window.core.idx.chat.query_attachment(
|
200
|
+
query=query,
|
201
|
+
path=idx_path,
|
202
|
+
model=model_item,
|
203
|
+
history=history_data,
|
204
|
+
verbose=verbose,
|
205
|
+
)
|
167
206
|
self.last_used_context = result
|
168
207
|
|
169
208
|
if self.is_verbose():
|
@@ -171,28 +210,12 @@ class Context:
|
|
171
210
|
|
172
211
|
return result
|
173
212
|
|
174
|
-
def
|
175
|
-
"""
|
176
|
-
Get selected model for attachments
|
177
|
-
|
178
|
-
:return: model name, model item
|
179
|
-
"""
|
180
|
-
model_item = None
|
181
|
-
model = None
|
182
|
-
if mode == "summary":
|
183
|
-
model = self.window.core.config.get("ctx.attachment.summary.model", "gpt-4o-mini")
|
184
|
-
elif mode == "query":
|
185
|
-
model = self.window.core.config.get("ctx.attachment.query.model", "gpt-4o-mini")
|
186
|
-
if model:
|
187
|
-
model_item = self.window.core.models.get(model)
|
188
|
-
return model, model_item
|
189
|
-
|
190
|
-
def summary_context(self, ctx: CtxItem, query: str) -> str:
|
213
|
+
def summary_context(self, ctx: CtxItem, history: list) -> str:
|
191
214
|
"""
|
192
215
|
Get summary of the context
|
193
216
|
|
194
217
|
:param ctx: CtxItem instance
|
195
|
-
:param
|
218
|
+
:param history: history
|
196
219
|
:return: query result
|
197
220
|
"""
|
198
221
|
model, model_item = self.get_selected_model("summary")
|
@@ -202,6 +225,7 @@ class Context:
|
|
202
225
|
if self.is_verbose():
|
203
226
|
print("Attachments: using summary model: {}".format(model))
|
204
227
|
|
228
|
+
query = str(ctx.input)
|
205
229
|
content = self.get_context_text(ctx, filename=True)
|
206
230
|
prompt = self.summary_prompt.format(
|
207
231
|
query=str(query).strip(),
|
@@ -210,12 +234,14 @@ class Context:
|
|
210
234
|
if self.is_verbose():
|
211
235
|
print("Attachments: summary prompt: {}".format(prompt))
|
212
236
|
|
237
|
+
history_data = self.prepare_context_history(history)
|
213
238
|
ctx = CtxItem()
|
214
239
|
bridge_context = BridgeContext(
|
215
240
|
ctx=ctx,
|
216
241
|
prompt=prompt,
|
217
242
|
stream=False,
|
218
243
|
model=model_item,
|
244
|
+
history=history_data,
|
219
245
|
)
|
220
246
|
event = KernelEvent(KernelEvent.CALL, {
|
221
247
|
'context': bridge_context,
|
@@ -228,6 +254,35 @@ class Context:
|
|
228
254
|
print("Attachments: summary received: {}".format(response))
|
229
255
|
return response
|
230
256
|
|
257
|
+
def prepare_context_history(self, history: list) -> list:
|
258
|
+
"""
|
259
|
+
Prepare context history
|
260
|
+
|
261
|
+
:param history: history
|
262
|
+
:return: history data
|
263
|
+
"""
|
264
|
+
use_history = self.window.core.config.get("ctx.attachment.rag.history", True)
|
265
|
+
history_data = []
|
266
|
+
if use_history:
|
267
|
+
if self.is_verbose():
|
268
|
+
print("Attachments: using history for query prepare...")
|
269
|
+
|
270
|
+
# use only last X items from history
|
271
|
+
num_items = self.window.core.config.get("ctx.attachment.rag.history.max_items", 3)
|
272
|
+
history_data = []
|
273
|
+
for item in history:
|
274
|
+
history_data.append(item)
|
275
|
+
|
276
|
+
# 0 = unlimited
|
277
|
+
if num_items > 0:
|
278
|
+
if self.is_verbose():
|
279
|
+
print("Attachments: using last {} items from history...".format(num_items))
|
280
|
+
if len(history_data) < num_items:
|
281
|
+
num_items = len(history_data)
|
282
|
+
history_data = history_data[-num_items:]
|
283
|
+
|
284
|
+
return history_data
|
285
|
+
|
231
286
|
def upload(
|
232
287
|
self,
|
233
288
|
meta: CtxMeta,
|
@@ -396,6 +451,41 @@ class Context:
|
|
396
451
|
print("Attachments: indexed. Doc IDs: {}".format(doc_ids))
|
397
452
|
return doc_ids
|
398
453
|
|
454
|
+
def get_all(self, meta: CtxMeta) -> list:
|
455
|
+
"""
|
456
|
+
Get all attachments for meta
|
457
|
+
|
458
|
+
:param meta: CtxMeta instance
|
459
|
+
:return: list of attachments
|
460
|
+
"""
|
461
|
+
return meta.additional_ctx
|
462
|
+
|
463
|
+
def get_dir(self, meta: CtxMeta) -> str:
|
464
|
+
"""
|
465
|
+
Get directory for meta
|
466
|
+
|
467
|
+
:param meta: CtxMeta instance
|
468
|
+
:return: directory path
|
469
|
+
"""
|
470
|
+
meta_uuid = str(meta.uuid)
|
471
|
+
return os.path.join(self.window.core.config.get_user_dir("ctx_idx"), meta_uuid)
|
472
|
+
|
473
|
+
def get_selected_model(self, mode: str = "summary"):
|
474
|
+
"""
|
475
|
+
Get selected model for attachments
|
476
|
+
|
477
|
+
:return: model name, model item
|
478
|
+
"""
|
479
|
+
model_item = None
|
480
|
+
model = None
|
481
|
+
if mode == "summary":
|
482
|
+
model = self.window.core.config.get("ctx.attachment.summary.model", "gpt-4o-mini")
|
483
|
+
elif mode == "query":
|
484
|
+
model = self.window.core.config.get("ctx.attachment.query.model", "gpt-4o-mini")
|
485
|
+
if model:
|
486
|
+
model_item = self.window.core.models.get(model)
|
487
|
+
return model, model_item
|
488
|
+
|
399
489
|
def duplicate(self, from_meta_id: int, to_meta_id: int) -> bool:
|
400
490
|
"""
|
401
491
|
Duplicate attachments from one meta to another
|
pygpt_net/core/bridge/worker.py
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# GitHub: https://github.com/szczyglis-dev/py-gpt #
|
7
7
|
# MIT License #
|
8
8
|
# Created By : Marcin Szczygliński #
|
9
|
-
# Updated Date: 2024.11.23
|
9
|
+
# Updated Date: 2024.11.29 23:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
from PySide6.QtCore import QObject, Signal, QRunnable, Slot
|
@@ -50,6 +50,9 @@ class BridgeWorker(QObject, QRunnable):
|
|
50
50
|
# ADDITIONAL CONTEXT: append additional context from attachments
|
51
51
|
self.handle_additional_context()
|
52
52
|
|
53
|
+
# POST PROMPT END: handle post prompt end event
|
54
|
+
self.handle_post_prompt_end()
|
55
|
+
|
53
56
|
# Langchain
|
54
57
|
if self.mode == MODE_LANGCHAIN:
|
55
58
|
result = self.window.core.chain.call(
|
@@ -124,6 +127,17 @@ class BridgeWorker(QObject, QRunnable):
|
|
124
127
|
self.window.dispatch(event)
|
125
128
|
self.context.system_prompt = event.data['value']
|
126
129
|
|
130
|
+
def handle_post_prompt_end(self):
|
131
|
+
"""Handle post prompt end event"""
|
132
|
+
event = Event(Event.POST_PROMPT_END, {
|
133
|
+
'mode': self.context.mode,
|
134
|
+
'reply': self.context.ctx.reply,
|
135
|
+
'value': self.context.system_prompt,
|
136
|
+
})
|
137
|
+
event.ctx = self.context.ctx
|
138
|
+
self.window.dispatch(event)
|
139
|
+
self.context.system_prompt = event.data['value']
|
140
|
+
|
127
141
|
def handle_additional_context(self):
|
128
142
|
"""Append additional context"""
|
129
143
|
ctx = self.context.ctx
|
@@ -133,7 +147,7 @@ class BridgeWorker(QObject, QRunnable):
|
|
133
147
|
return
|
134
148
|
if not self.window.controller.chat.attachment.has_context(ctx.meta):
|
135
149
|
return
|
136
|
-
ad_context = self.window.controller.chat.attachment.get_context(ctx)
|
150
|
+
ad_context = self.window.controller.chat.attachment.get_context(ctx, self.context.history)
|
137
151
|
ad_mode = self.window.controller.chat.attachment.get_mode()
|
138
152
|
if ad_context:
|
139
153
|
self.context.prompt += "\n\n" + ad_context # append to input text
|
pygpt_net/core/events/event.py
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# GitHub: https://github.com/szczyglis-dev/py-gpt #
|
7
7
|
# MIT License #
|
8
8
|
# Created By : Marcin Szczygliński #
|
9
|
-
# Updated Date: 2024.11.
|
9
|
+
# Updated Date: 2024.11.29 23:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
import json
|
@@ -50,6 +50,7 @@ class Event(BaseEvent):
|
|
50
50
|
PLUGIN_OPTION_GET = "plugin.option.get"
|
51
51
|
POST_PROMPT = "post.prompt"
|
52
52
|
POST_PROMPT_ASYNC = "post.prompt.async"
|
53
|
+
POST_PROMPT_END = "post.prompt.end"
|
53
54
|
PRE_PROMPT = "pre.prompt"
|
54
55
|
SYSTEM_PROMPT = "system.prompt"
|
55
56
|
TOOL_OUTPUT_RENDER = "tool.output.render"
|