Compare commits

..

8 Commits

Author SHA1 Message Date
Jared Van Bortel
1731e7929c embllm: stop embdding loop on exit
This is especially important on CPU, when we may spend many hours
embedding a colection of documents.

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
2025-02-05 18:55:55 -05:00
Jared Van Bortel
4e18c81107 guard logger QFile access with a mutex
This fixes the following assertion failure in Qt debug builds:
```
ASSERT: "bytes <= bufferSize" in file C:\Users\qt\work\qt\qtbase\src\corelib\tools\qringbuffer.cpp, line 75
```

The message handler is called from the thread that sends the message, so
we need to make sure only one thread can access the file at a time,
since QFile is not inherently threadsafe.

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
2025-02-05 18:18:55 -05:00
Jared Van Bortel
350bd0a793 do not assert that network requests have a valid status code
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
2025-02-05 16:32:22 -05:00
Jared Van Bortel
2d065bb3bc add changelog entry
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
2025-02-05 11:45:55 -05:00
Jared Van Bortel
01b9773866 translations: fix duplicate string
This entry causes the Visual Studio build to fail.

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
2025-02-05 11:38:17 -05:00
Jared Van Bortel
82e543e6b9 chatmodel: fix call of setParent from wrong thread
Attempting to notify the objects of this change from a different thread
causes an error in debug builds:

```
ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to
objects owned by a a different thread. Current thread 0x0x1a9dc360490.
Receiver '' (of type 'ChatModel') was created in thread
0x0x1a9ad1a99f0", file
C:\Users\qt\work\qtbase\src\corelib\kernel\qcoreapplication.cpp, line
557
```

QObject::setParent is not documented to be thread-safe.

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
2025-02-05 11:38:17 -05:00
Jared Van Bortel
17bbedc77c llmodel: do not crash on nonexistent dir in impl search path
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
2025-02-05 11:38:17 -05:00
Jared Van Bortel
3acbfcf92c database: fix DocumentInfo stack-use-after-return
`info` is local to scanQueue, so we have to store a copy in the
DocumentReader to extend its lifetime. Not sure how this even worked
before.

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
2025-02-05 11:38:17 -05:00
9 changed files with 17 additions and 108 deletions

View File

@@ -1903,22 +1903,22 @@ workflows:
context: gpt4all
- build-offline-chat-installer-linux:
context: gpt4all
- sign-offline-chat-installer-macos:
- sign-online-chat-installer-macos:
context: gpt4all
requires:
- build-offline-chat-installer-macos
- notarize-offline-chat-installer-macos:
- build-online-chat-installer-macos
- notarize-online-chat-installer-macos:
context: gpt4all
requires:
- sign-offline-chat-installer-macos
- sign-offline-chat-installer-windows:
- sign-online-chat-installer-macos
- sign-online-chat-installer-windows:
context: gpt4all
requires:
- build-offline-chat-installer-windows
- sign-offline-chat-installer-windows-arm:
- build-online-chat-installer-windows
- sign-online-chat-installer-windows-arm:
context: gpt4all
requires:
- build-offline-chat-installer-windows-arm
- build-online-chat-installer-windows-arm
build-chat-installers-release:
# only run on main branch tags that start with 'v' and a digit
when:

View File

@@ -72,6 +72,6 @@ Discord: `@Tim453`
- Flatpak
Jack ([@wuodoo](https://github.com/wuodoo))<br/>
E-mail: 2296103047@qq.com<br/>
E-mail: 2296103047@qq.com><br/>
Discord: `@mikage`
- zh\_CN translation

View File

@@ -53,7 +53,6 @@ static const std::vector<const char *> KNOWN_ARCHES {
"gpt2",
// "gptj", -- no inference code
"gptneox",
"granite",
"granitemoe",
"mpt",
"baichuan",

View File

@@ -6,15 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
## [Unreleased]
### Added
- Whitelist Granite (non-MoE) model architecture (by [@ThiloteE](https://github.com/ThiloteE) in [#3487](https://github.com/nomic-ai/gpt4all/pull/3487))
### Changed
- Substitute prettier default templates for OLMoE 7B 0924/0125 and Granite 3.1 3B/8B (by [@ThiloteE](https://github.com/ThiloteE) in [#3471](https://github.com/nomic-ai/gpt4all/pull/3471))
### Fixed
- Fix several potential crashes ([#3465](https://github.com/nomic-ai/gpt4all/pull/3465))
- Fix visual spacing issues with deepseek models ([#3470](https://github.com/nomic-ai/gpt4all/pull/3470))
## [3.9.0] - 2025-02-04

View File

@@ -198,7 +198,6 @@ GridLayout {
isError: false
isThinking: true
thinkingTime: modelData.thinkingTime
visible: modelData.content !== ""
}
}
}

View File

@@ -976,8 +976,7 @@ public:
{
Q_UNUSED(bufferIdx)
try {
QString r = response;
m_cllm->m_chatModel->setResponseValue(removeLeadingWhitespace(r));
m_cllm->m_chatModel->setResponseValue(response);
} catch (const std::exception &e) {
// We have a try/catch here because the main thread might have removed the response from
// the chatmodel by erasing the conversation during the response... the main thread sets
@@ -992,7 +991,7 @@ public:
bool onRegularResponse() override
{
auto respStr = QString::fromUtf8(m_result->response);
return onBufferResponse(respStr, 0);
return onBufferResponse(removeLeadingWhitespace(respStr), 0);
}
bool getStopGenerating() const override
@@ -1079,7 +1078,7 @@ auto ChatLLM::promptInternal(
auto respStr = QString::fromUtf8(result.response);
if (!respStr.isEmpty() && (std::as_const(respStr).back().isSpace() || finalBuffers.size() > 1)) {
if (finalBuffers.size() > 1)
m_chatModel->setResponseValue(finalBuffers.last().trimmed());
m_chatModel->setResponseValue(finalBuffers.last());
else
m_chatModel->setResponseValue(respStr.trimmed());
emit responseChanged();

View File

@@ -281,6 +281,9 @@ void EmbeddingLLMWorker::docEmbeddingsRequested(const QVector<EmbeddingChunk> &c
std::vector<float> result;
result.resize(chunks.size() * m_model->embeddingSize());
for (int j = 0; j < chunks.size(); j += BATCH_SIZE) {
if (m_stopGenerating)
return;
QMutexLocker locker(&m_mutex);
std::vector batchTexts(texts.begin() + j, texts.begin() + std::min(j + BATCH_SIZE, int(texts.size())));
try {

View File

@@ -113,31 +113,11 @@ const std::unordered_map<std::string_view, std::string_view> CHAT_TEMPLATE_SUBST
{%- elif message['role'] == 'system' %}
{{- '<|system|>\n' + message['content'] + eos_token }}
{%- elif message['role'] == 'assistant' %}
{{- '<|assistant|>\n' + message['content'] + eos_token }}
{{- '<|assistant|>\n' + message['content'] + eos_token }}
{%- endif %}
{%- if loop.last and add_generation_prompt %}
{{- '<|assistant|>' }}
{%- endif %}
{%- endfor %})TEMPLATE",
},
// granite-3.1-3b-a800m-instruct-Q4_0.gguf, granite-3.1-8b-instruct-Q4_0.gguf (nomic-ai/gpt4all#3471)
{
// original
R"TEMPLATE({%- if messages[0]['role'] == 'system' %}{%- set system_message = messages[0]['content'] %}{%- set loop_messages = messages[1:] %}{%- else %}{%- set system_message = "Knowledge Cutoff Date: April 2024. You are Granite, developed by IBM." %}{%- if tools and documents %}{%- set system_message = system_message + " You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request. Write the response to the user's input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data." %}{%- elif tools %}{%- set system_message = system_message + " You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request." %}{%- elif documents %}{%- set system_message = system_message + " Write the response to the user's input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data." %}{%- else %}{%- set system_message = system_message + " You are a helpful AI assistant." %}{%- endif %}{%- if controls and 'citations' in controls and documents %}{%- set system_message = system_message + ' In your response, use the symbols <co> and </co> to indicate when a fact comes from a document in the search result, e.g <co>0</co> for a fact from document 0. Afterwards, list all the citations with their corresponding documents in an ordered list.' %}{%- endif %}{%- if controls and 'hallucinations' in controls and documents %}{%- set system_message = system_message + ' Finally, after the response is written, include a numbered list of sentences from the response that are potentially hallucinated and not based in the documents.' %}{%- endif %}{%- set loop_messages = messages %}{%- endif %}{{- '<|start_of_role|>system<|end_of_role|>' + system_message + '<|end_of_text|> ' }}{%- if tools %}{{- '<|start_of_role|>tools<|end_of_role|>' }}{{- tools | tojson(indent=4) }}{{- '<|end_of_text|> ' }}{%- endif %}{%- if documents %}{{- '<|start_of_role|>documents<|end_of_role|>' }}{%- for document in documents %}{{- 'Document ' + loop.index0 | string + ' ' }}{{- document['text'] }}{%- if not loop.last %}{{- ' '}}{%- endif%}{%- endfor %}{{- '<|end_of_text|> ' }}{%- endif %}{%- for message in loop_messages %}{{- '<|start_of_role|>' + message['role'] + '<|end_of_role|>' + message['content'] + '<|end_of_text|> ' }}{%- if loop.last and add_generation_prompt %}{{- '<|start_of_role|>assistant' }}{%- if controls %}{{- ' ' + controls | tojson()}}{%- endif %}{{- '<|end_of_role|>' }}{%- endif %}{%- endfor %})TEMPLATE",
// replacement
R"TEMPLATE({%- if messages[0]['role'] == 'system' %}
{%- set system_message = messages[0]['content'] %}
{%- set loop_messages = messages[1:] %}
{%- else %}
{%- set system_message = "Knowledge Cutoff Date: April 2024. You are Granite, developed by IBM. You are a helpful AI assistant." %}
{%- set loop_messages = messages %}
{%- endif %}
{{- '<|start_of_role|>system<|end_of_role|>' + system_message + '<|end_of_text|> ' }}
{%- for message in loop_messages %}
{{- '<|start_of_role|>' + message['role'] + '<|end_of_role|>' + message['content'] + '<|end_of_text|> ' }}
{%- if loop.last and add_generation_prompt %}
{{- '<|start_of_role|>assistant<|end_of_role|>' }}
{%- endif %}
{%- endfor %})TEMPLATE",
},
// Hermes-3-Llama-3.2-3B.Q4_0.gguf, mistral-7b-openorca.gguf2.Q4_0.gguf
@@ -638,70 +618,6 @@ const std::unordered_map<std::string_view, std::string_view> CHAT_TEMPLATE_SUBST
{%- if add_generation_prompt %}
{{- '<|im_start|>assistant\n' }}
{%- endif %})TEMPLATE",
},
// OLMoE-1B-7B-0125-Instruct-Q4_0.gguf (nomic-ai/gpt4all#3471)
{
// original
R"TEMPLATE({{ bos_token }}{% for message in messages %}{% if message['role'] == 'system' %}{{ '<|system|>
' + message['content'] + '
' }}{% elif message['role'] == 'user' %}{{ '<|user|>
' + message['content'] + '
' }}{% elif message['role'] == 'assistant' %}{% if not loop.last %}{{ '<|assistant|>
' + message['content'] + eos_token + '
' }}{% else %}{{ '<|assistant|>
' + message['content'] + eos_token }}{% endif %}{% endif %}{% if loop.last and add_generation_prompt %}{{ '<|assistant|>
' }}{% endif %}{% endfor %})TEMPLATE",
// replacement
R"TEMPLATE({{- bos_token }}
{%- for message in messages %}
{%- if message['role'] == 'system' %}
{{- '<|system|>\n' + message['content'] + '\n' }}
{%- elif message['role'] == 'user' %}
{{- '<|user|>\n' + message['content'] + '\n' }}
{%- elif message['role'] == 'assistant' %}
{%- if not loop.last %}
{{- '<|assistant|>\n' + message['content'] + eos_token + '\n' }}
{%- else %}
{{- '<|assistant|>\n' + message['content'] + eos_token }}
{%- endif %}
{%- endif %}
{%- if loop.last and add_generation_prompt %}
{{- '<|assistant|>\n' }}
{%- endif %}
{%- endfor %})TEMPLATE",
},
// OLMoE-1B-7B-0924-Instruct-Q4_0.gguf (nomic-ai/gpt4all#3471)
{
// original
R"TEMPLATE({{ bos_token }}{% for message in messages %}
{% if message['role'] == 'system' %}
{{ '<|system|>
' + message['content'] }}
{% elif message['role'] == 'user' %}
{{ '<|user|>
' + message['content'] }}
{% elif message['role'] == 'assistant' %}
{{ '<|assistant|>
' + message['content'] + eos_token }}
{% endif %}
{% if loop.last and add_generation_prompt %}
{{ '<|assistant|>' }}
{% endif %}
{% endfor %})TEMPLATE",
// replacement
R"TEMPLATE({{- bos_token }}
{%- for message in messages %}
{%- if message['role'] == 'system' %}
{{- '<|system|>\n' + message['content'] }}
{%- elif message['role'] == 'user' %}
{{- '<|user|>\n' + message['content'] }}
{%- elif message['role'] == 'assistant' %}
{{- '<|assistant|>\n' + message['content'] + eos_token }}
{%- endif %}
{%- if loop.last and add_generation_prompt %}
{{- '<|assistant|>' }}
{%- endif %}
{%- endfor %})TEMPLATE",
},
// Phi-3.1-mini-128k-instruct-Q4_0.gguf (nomic-ai/gpt4all#3346)
{