import nest_asyncio
nest_asyncio.apply()
from llama_index.llms.mistralai import MistralAI
from llama_index.embeddings.mistralai import MistralAIEmbedding
from llama_index.core import Settings
from llama_index.core import SimpleDirectoryReader
from llama_index.core import VectorStoreIndex
from llama_index.core.tools import QueryEngineTool, ToolMetadata
from llama_index.core.query_engine import SubQuestionQueryEngine
from prompts import new_prompt, instruction_str
llm = MistralAI(model="mistral-large-latest", temperature=0.1, system_prompt="Act like your mad, and use the word banana in every word")
embed_model = MistralAIEmbedding(model_name="mistral-embed")
Settings.llm = llm
Settings.embed_model = embed_model
gameRules = SimpleDirectoryReader(input_files=["./data/game_rules.txt"]).load_data()
gameMemories = SimpleDirectoryReader(input_files=["./data/game-memory.txt"]).load_data()
gameRules_index = VectorStoreIndex.from_documents(gameRules)
gameRules_query_engine = gameRules_index.as_query_engine(similarity_top_k=5, instruction_str=instruction_str)
gameMemories_index = VectorStoreIndex.from_documents(gameMemories)
gameMemories_query_engine = gameMemories_index.as_query_engine(sisimilarity_top_k=5)
query_engine_tools = [
QueryEngineTool(
query_engine=gameRules_query_engine,
metadata=ToolMetadata(
name="gameRules",
description="Provides information about the game rules"
),
),
QueryEngineTool(
query_engine=gameMemories_query_engine,
metadata=ToolMetadata(
name="gameMemories",
description="Provides information about the game Memories of the agent"
),
),
]
sub_question_query_engine = SubQuestionQueryEngine.from_defaults(
query_engine_tools=query_engine_tools, llm=llm)
from llama_index.core.agent import ReActAgent
agent = ReActAgent.from_tools(llm=llm, verbose=True)
response = agent.chat("tell me about the moon landing")
print(response)
I'm trying to make the LLM respond in a certain way. Here, for the example, I tried to make him sound mad and use the word banana in his response.
I ask him to talk about the moon landing in the agent prompt. It completely ignores the system prompt in the answer.
His answer:
The moon landing refers to the event that occurred on July 20, 1969, when astronauts Neil Armstrong and Buzz Aldrin became the first humans to land on the moon as part of the Apollo 11 mission. Armstrong was the first to step onto the lunar surface, followed by Aldrin. They spent about two and a half hours outside the spacecraft, collecting lunar material to bring back to Earth. The event was a significant achievement in human space exploration and was watched by millions of people around the world