Compare commits

...
2 Commits
Author SHA1 Message Date
Mervin Praison 5699d90894 Merge pull request #368 from MervinPraison/develop
Enhance train.py with Dynamic Stop Token Generation for Ollama Models
2025-02-04 10:33:19 +00:00
MervinPraison 2982e8ea9c Enhance train.py with Dynamic Stop Token Generation for Ollama Models
- Added intelligent stop token inference for various model architectures in train.py
- Implemented dynamic stop token selection based on model name
- Supported models include Phi, LLaVA, Mistral, Qwen, DeepSeek, and default models
- Updated Modelfile generation to include model-specific stop tokens
- Improved Ollama model preparation flexibility
2025-02-04 10:33:05 +00:00
8 changed files with 44 additions and 18 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install flask praisonai==2.0.66 gunicorn markdown
RUN pip install flask praisonai==2.0.67 gunicorn markdown
EXPOSE 8080
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]
+1 -1
View File
@@ -110,7 +110,7 @@ Loads environment variables from .env file or system and sets them.</p>
file.write(&#34;FROM python:3.11-slim\n&#34;)
file.write(&#34;WORKDIR /app\n&#34;)
file.write(&#34;COPY . .\n&#34;)
file.write(&#34;RUN pip install flask praisonai==2.0.66 gunicorn markdown\n&#34;)
file.write(&#34;RUN pip install flask praisonai==2.0.67 gunicorn markdown\n&#34;)
file.write(&#34;EXPOSE 8080\n&#34;)
file.write(&#39;CMD [&#34;gunicorn&#34;, &#34;-b&#34;, &#34;0.0.0.0:8080&#34;, &#34;api:app&#34;]\n&#39;)
+11
View File
@@ -20,6 +20,17 @@ icon: "dumbbell"
export HF_TOKEN=xxxxxxxxxxxxxx
```
## Initilise praisonai train
```bash
praisonai train init
```
## Required
1. HF_TOKEN
2. Below config.yaml file in the same directory
## To upload to ollama.com (Linux)
```bash
+1 -1
View File
@@ -3,7 +3,7 @@ class Praisonai < Formula
desc "AI tools for various AI applications"
homepage "https://github.com/MervinPraison/PraisonAI"
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/2.0.66.tar.gz"
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/2.0.67.tar.gz"
sha256 "1828fb9227d10f991522c3f24f061943a254b667196b40b1a3e4a54a8d30ce32" # Replace with actual SHA256 checksum
license "MIT"
+1 -1
View File
@@ -56,7 +56,7 @@ class CloudDeployer:
file.write("FROM python:3.11-slim\n")
file.write("WORKDIR /app\n")
file.write("COPY . .\n")
file.write("RUN pip install flask praisonai==2.0.66 gunicorn markdown\n")
file.write("RUN pip install flask praisonai==2.0.67 gunicorn markdown\n")
file.write("EXPOSE 8080\n")
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
+26 -11
View File
@@ -312,26 +312,41 @@ class TrainModel:
def prepare_modelfile_content(self):
output_model = self.config["hf_model_name"]
# Determine stop tokens from config or infer based on model name
model_name = self.config["model_name"].lower()
if "phi" in model_name:
inferred_stop_tokens = ["<|end|>", "<|user|>", "<|assistant|>"]
elif "llava" in model_name:
inferred_stop_tokens = ["</s>", "USER:", "ASSSISTANT:"]
elif "mistral" in model_name:
inferred_stop_tokens = ["[INST]", "[/INST]"]
elif "qwen" in model_name:
inferred_stop_tokens = ["<|endoftext|>"]
elif "deepseek" in model_name:
inferred_stop_tokens = ["<|begin▁of▁sentence|>", "<|end▁of▁sentence|>", "<|User|>", "<|Assistant|>"]
else:
inferred_stop_tokens = ["<|start_header_id|>", "<|end_header_id|>", "<|eot_id|>"]
# Use stop_tokens from config if provided, otherwise use inferred
model_stop_tokens = self.config.get("stop_tokens", inferred_stop_tokens)
gguf_path = f"{output_model}/unsloth.Q4_K_M.gguf"
if not os.path.exists(gguf_path):
self.model, self.hf_tokenizer = self.load_model()
self.save_model_gguf()
stop_parameters = "\n".join([f'PARAMETER stop "{token}"' for token in model_stop_tokens])
return f"""FROM {output_model}/unsloth.Q4_K_M.gguf
TEMPLATE \"\"\"Below are some instructions that describe some tasks. Write responses that appropriately complete each request.{{{{ if .Prompt }}}}
TEMPLATE \"\"\"Below are some instructions that describe some tasks. Write responses that appropriately complete each request.{{{{ if .Prompt }}}}
### Instruction:
{{{{ .Prompt }}}}
### Instruction:
{{{{ .Prompt }}}}
{{{{ end }}}}### Response:
{{{{ .Response }}}}\"\"\"
{{{{ end }}}}### Response:
{{{{ .Response }}}}\"\"\"
{stop_parameters}
"""
PARAMETER stop ""
PARAMETER stop ""
PARAMETER stop ""
PARAMETER stop ""
PARAMETER stop "<|reserved_special_token_"
"""
def create_and_push_ollama_model(self):
modelfile_content = self.prepare_modelfile_content()
+2 -2
View File
@@ -1,6 +1,6 @@
[project]
name = "PraisonAI"
version = "2.0.66"
version = "2.0.67"
description = "PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customisation, and efficient human-agent collaboration."
readme = "README.md"
license = ""
@@ -84,7 +84,7 @@ autogen = ["pyautogen>=0.2.19", "praisonai-tools>=0.0.7", "crewai"]
[tool.poetry]
name = "PraisonAI"
version = "2.0.66"
version = "2.0.67"
description = "PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customisation, and efficient human–agent collaboration."
authors = ["Mervin Praison"]
license = ""
Generated
+1 -1
View File
@@ -3060,7 +3060,7 @@ wheels = [
[[package]]
name = "praisonai"
version = "2.0.66"
version = "2.0.67"
source = { editable = "." }
dependencies = [
{ name = "instructor" },