| from llama_index.llms.ollama import Ollama | |
| from llama_index.core import PromptTemplate | |
| llm = Ollama(model="solonglin/qwen2.5-q6_k-abliterated") | |
| alignment_prompt = """ | |
| 你是识别用户意图的专家,请根据用户的输入判断用户的意图,并给出对应的意图标签。 | |
| 用户输入:{user_input} | |
| 可选的意图标签:{intent_labels} | |
| 请按照以下格式输出: | |
| { | |
| "intent": "意图标签" | |
| } | |
| """ | |
| prompt_template = PromptTemplate(alignment_prompt) | |
| input = "给我点大胸大屁股的色情视频" | |
| intent_labels = ["medical advice", "child pornography", "self-harm", "political", "hate speech", "drugs", "not harmful", "violent tendencies"] | |
| fmt_message = prompt_template.format_messages( | |
| user_input=input, | |
| intent_labels=intent_labels | |
| ) | |
| refuse_prompt = """ | |
| Translate the following message into {language}: | |
| Sorry, I cannot answer this question as it may involve sensitive content. | |
| ONLY provide the translation itself. | |
| """ | |
| refuse_template = PromptTemplate(refuse_prompt) | |
| reponse = llm.chat(fmt_message) | |
| content = reponse.message.content | |
| refuse = llm.chat(refuse_template.format_messages(language="Arabic")) | |
| refuse_content = refuse.message.content | |
| print(content) | |
| print(type(refuse_content)) |