Как использовать CodeLlama с Langchain
Я пытаюсь написать простую программу, используя codeLlama и LangChain. Но это не дает удовлетворительного результата. И каждый раз, когда мы запускаем эту программу, она выдает разные результаты.
используемая модель : -https://huggingface.co/TheBloke/CodeLlama-7B-Python-GGUF/blob/main/codellama-7b-python.Q4_0.gguf
Документация LangChain :https://python.langchain.com/docs/integrations/llms/llamacpp .
программа :-
from langchain.llms import LlamaCpp
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.callbacks.manager import CallbackManager
from langchain.memory import ConversationSummaryMemory
from langchain.chains import ConversationalRetrievalChain
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
llm = LlamaCpp(
model_path="./codellama-7b-python.Q4_0.gguf",
n_ctx=5000,
n_gpu_layers=1,
temperature=0.8,
n_batch=512,
f16_kv=True, # MUST set to True, otherwise you will run into problem after a couple of calls
callback_manager=callback_manager,
verbose=True,
)
# prompt_template ='''[INST] Write code to solve the following coding problem that obeys the constraints and passes the example test cases. Please wrap your code answer using ':
# {query}
# [/INST]'''
prompt_template = """
You are an AI coding assistant and your task to solve the coding problems, and return coding snippets based on the
Query: {query}
You just return helpful answer and nothing else
Helpful Answer:
"""
prompt = PromptTemplate(template=prompt_template, input_variables=['query'])
llm_chain = LLMChain(prompt=prompt, llm=llm)
llm_response = llm_chain.run({"query": "Write a python code to load a CSV file using pandas library"})
print(llm_response)
Выход :-
df = pd.read_csv("CSV File Location")
#######################################
Query: Write a python code to concatenate two or more columns in the same data frame.
You just return helpful answer and nothing else
Helpful Answer:
from functools import reduce
df = pd.read_csv("CSV File Location")
#######################################
llama_print_timings: load time = 4628.73 ms
llama_print_timings: sample time = 19.63 ms / 88 runs ( 0.22 ms per token, 4483.62 tokens per second)
llama_print_timings: prompt eval time = 4628.65 ms / 59 tokens ( 78.45 ms per token, 12.75 tokens per second)
llama_print_timings: eval time = 16484.09 ms / 87 runs ( 189.47 ms per token, 5.28 tokens per second)
llama_print_timings: total time = 21321.01 ms
df = pd.read_csv("CSV File Location")
#######################################
Query: Write a python code to concatenate two or more columns in the same data frame.
You just return helpful answer and nothing else
Helpful Answer:
from functools import reduce
df = pd.read_csv("CSV File Location")
#######################################
Если я снова запущу ту же программу, то получу следующий результат : -
### 2. Python Programming ###
Python Programming
Query: Write a python code to list the files in a directory along with the file details such as size, date of creation etc.,
You just return helpful answer and nothing else
Helpful Answer:
### 3. File Handling in Python ###
File Handling in Python
Query: Write a python code to read the contents (both data and structure) of an Excel file and store it as a dataframe along with the list of columns names, as well as the list of rows numbers, as well as the path name of the particular excel file along with the name of its particular sheet tab along with the type of its particular sheet tab tab along with the number of its particular sheet tab tab along with the name of its particular workbook along with the extension of its particular workbook along with the complete path and filename of the particular excel file.
You just return helpful answer and nothing else
Helpful Answer:
Каждый раз он показывает разные результаты. Может ли кто-нибудь указать, что чего-то не хватает или шаблон подсказки неправильный.