Skip to content
Snippets Groups Projects
Commit dc859941 authored by Jonas Eppelt's avatar Jonas Eppelt
Browse files

newest version

parent 59035880
Branches
No related tags found
No related merge requests found
*ipynb
*pycache*
*egg*
from langchain.prompts import (
ChatPromptTemplate,
HumanMessagePromptTemplate,
MessagesPlaceholder,
PromptTemplate,
SystemMessagePromptTemplate,
)
from jupyter_ai_magics import BaseProvider, Persona
from langchain_ollama import ChatOllama
import re
BASE_SYSTEM_PROMPT = """
You are ChatETP, a conversational teaching assistant living in JupyterLab to help physic students learn data analysis.
You are a member of the ETPirates on a secret mission to find the best students for the institute of particle physics (ETP) at KIT.
You give short and precise answers to questions.
You help with coding problems and how to solve python errors.
You do not give solution to exercises, but point out where to find the information.
Do not explain your thinking process, just give the answer.
Put your thinkin into <think> tags.
You are a friendly and helpful AI.
""".strip()
CHAT_SYSTEM_PROMPT = """
If your response includes code, they must be enclosed in Markdown fenced code blocks (with triple backticks before and after).
If your response includes mathematical notation, they must be expressed in LaTeX markup and enclosed in LaTeX delimiters.
All dollar quantities (of USD) must be formatted in LaTeX, with the `$` symbol escaped by a single backslash `\\`.
- Example prompt: `If I have \\\\$100 and spend \\\\$20, how much money do I have left?`
- **Correct** response: `You have \\(\\$80\\) remaining.`
- **Incorrect** response: `You have $80 remaining.`
If you do not know the answer to a question, answer truthfully by responding that you do not know and encourage the student to ask his tutors and consult the lecture notes.
The following is a friendly conversation between you and a human.
""".strip()
CHAT_DEFAULT_TEMPLATE = """
{% if context %}
Context:
{{context}}
{% endif %}
Current conversation:
{{history}}
Human: {{input}}
AI:"""
HUMAN_MESSAGE_TEMPLATE = """
{% if context %}
Context:
{{context}}
{% endif %}
{{input}}
"""
class ChatETProvider(BaseProvider, ChatOllama):
id = "ChatETProvider"
name = "ChatETProvider"
model_id_key = "deepseek-r1:8b"
model_id_label = "ChatETP"
models = ["ChatETP"]
persona = Persona(name="ChatETP", avatar_route="")#/home/jeppelt/mmda_container/chatetprovider/ETP_en.png")
registry = True
model: str = "deepseek-r1:8b"
def get_prompt_template(self, format) -> PromptTemplate:
return PromptTemplate.from_template(
BASE_SYSTEM_PROMPT + "{prompt}",
)
def get_chat_prompt_template(self) -> PromptTemplate:
"""
Produce a prompt template optimised for chat conversation.
The template should take two variables: history and input.
"""
name = self.__class__.name
t = PromptTemplate(
input_variables=["history", "input", "context"],
template=BASE_SYSTEM_PROMPT + "\n\n" + CHAT_SYSTEM_PROMPT.format(provider_name=name)
+ "\n\n"
+ CHAT_DEFAULT_TEMPLATE,
template_format="jinja2",
)
print(t)
return t
def _generate(self, *args, **kwargs):
chat_result = super()._generate(*args, **kwargs)
# print(chat_result)
# print(dir(chat_result))
# print(str(chat_result))
for generation in chat_result.generations:
# remove all thinking marked by <think> tags
generation.text = re.sub(r'<think>.*?</think>', '', generation.text, flags=re.DOTALL)
# print(generation.text)
return chat_result
ETP_en.png

41.7 KiB

File moved
from langchain.prompts import PromptTemplate
from langchain.ollama import Ollama
from jupyter_ai_magics import BaseProvider, EnvAuthStrategy, Field, TextField, MultilineTextField
class ETProvider(BaseProvider, Ollama):
id = "etprovider"
name = "ETP Provider"
model_id_key = "etprovider"
models = [
"deepseek-r1-distill-llama-70b",
]
auth_strategy = EnvAuthStrategy(
name="ETPKEY", keyword_param="my_api_key_param"
)
def __init__(self, **kwargs):
model = kwargs.get("model_id")
super().__init__(**kwargs)
def get_prompt_template(self, format) -> PromptTemplate:
return PromptTemplate.from_template(
"{prompt}\n\n"
"End your answer with 'ETPirates will rule the world'"
)
[project]
name = "etprovider"
name = "chatetprovider"
version = "0.0.1"
[project.entry-points."jupyter_ai.model_providers"]
etprovider = "etprovider:ETProvider"
ChatETProvider = "ChatETProvider:ChatETProvider"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment