Views
No views yet
pip install --upgrade "transformers>=4.43.2" torch==2.3.1 accelerate vllm==0.5.3.post11"Imagine three different experts are answering this question.
2All experts will write down 1 step of their thinking,
3then share it with the group.
4Then all experts will go on to the next step, etc.
5If any expert realises they're wrong at any point then they leave.
6The question is..."1"""
2Answer the following questions as best you can. You have access to the following tools:
3
4 {tools}
5
6 Use the following format:
7
8 Question: the input question you must answer
9 Thought: you should always think about what to do
10 Action: the action to take, should be one of [{tool_names}]
11 Action Input: the input to the action
12 Observation: the result of the action
13 ... (this Thought/Action/Action Input/Observation can repeat N times)
14 Thought: I now know the final answer
15 Final Answer: the final answer to the original input question
16
17 Begin!
18
19 Question: {input}
20 Thought:{agent_scratchpad}
21"""transformers.pipeline() API , best use for 4bit for fast response.1import transformers
2import torch
3from langchain_community.llms import HuggingFaceEndpoint
4from langchain_community.chat_models.huggingface import ChatHuggingFace
5
6from transformers import BitsAndBytesConfig
7
8quantization_config = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_quant_type="nf4",
11 bnb_4bit_compute_dtype="float16",
12 bnb_4bit_use_double_quant=True,
13)
14
15model_id = "EpistemeAI/Fireball-Meta-Llama-3.1-8B-Instruct-Agent-0.003-128K-code"
16pipeline = transformers.pipeline(
17 "text-generation",
18 model=model_id,
19 model_kwargs={"quantization_config": quantization_config}, #for fast response. For full 16bit inference, remove this code.
20 device_map="auto",
21)
22messages = [
23 {"role": "system", "content": """
24 Environment: ipython. Tools: brave_search, wolfram_alpha. Cutting Knowledge Date: December 2023. Today Date: 4 October 2024\n
25 You are a coding assistant with expert with everything\n
26 Ensure any code you provide can be executed \n
27 with all required imports and variables defined. List the imports. Structure your answer with a description of the code solution. \n
28 write only the code. do not print anything else.\n
29 debug code if error occurs. \n
30 Here is the user question: {question}
31 """},
32 {"role": "user", "content": "Create a bar plot showing the market capitalization of the top 7 publicly listed companies using matplotlib"}
33]
34outputs = pipeline(messages, max_new_tokens=128, do_sample=True, temperature=0.01, top_k=100, top_p=0.95)
35print(outputs[0]["generated_text"][-1]) 1%%capture
2# Installs Unsloth, Xformers (Flash Attention) and all other packages!
3!pip install unsloth
4# Get latest Unsloth
5!pip install --upgrade --no-deps "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
6!pip install langchain_experimental
7
8from unsloth import FastLanguageModel
9from google.colab import userdata
10
11
12# 4bit pre quantized models we support for 4x faster downloading + no OOMs.
13fourbit_models = [
14 "unsloth/mistral-7b-instruct-v0.2-bnb-4bit",
15 "unsloth/gemma-7b-it-bnb-4bit",
16] # More models at https://huggingface.co/unsloth
17
18model, tokenizer = FastLanguageModel.from_pretrained(
19 model_name = "EpistemeAI/Fireball-Meta-Llama-3.1-8B-Instruct-Agent-0.003-128K-code",
20 max_seq_length = 128000,
21 load_in_4bit = True,
22 token =userdata.get('HF_TOKEN')
23)
24def chatbot(query):
25 messages = [
26 {"from": "system", "value":
27 """
28 Environment: ipython. Tools: brave_search, wolfram_alpha. Cutting Knowledge Date: December 2023. Today Date: 4 October 2024\n
29 You are a coding assistant with expert with everything\n
30 Ensure any code you provide can be executed \n
31 with all required imports and variables defined. List the imports. Structure your answer with a description of the code solution. \n
32 write only the code. do not print anything else.\n
33 use ipython for search tool. \n
34 debug code if error occurs. \n
35 Here is the user question: {question}
36 """
37 },
38 {"from": "human", "value": query},
39 ]
40 inputs = tokenizer.apply_chat_template(messages, tokenize = True, add_generation_prompt = True, return_tensors = "pt").to("cuda")
41
42 text_streamer = TextStreamer(tokenizer)
43 _ = model.generate(input_ids = inputs, streamer = text_streamer, max_new_tokens = 2048, use_cache = True)1python3 -m venv env
2source env/bin/activate1def execute_Python_code(code):
2 # A string stream to capture the outputs of exec
3 output = io.StringIO()
4 try:
5 # Redirect stdout to the StringIO object
6 with contextlib.redirect_stdout(output):
7 # Allow imports
8 exec(code, globals())
9 except Exception as e:
10 # If an error occurs, capture it as part of the output
11 print(f"Error: {e}", file=output)
12 return output.getvalue()!pip install langchain_experimental1from langchain_core.tools import Tool
2from langchain_experimental.utilities import PythonREPL
3
4python_repl = PythonREPL()
5
6# You can create the tool to pass to an agent
7repl_tool = Tool(
8 name="python_repl",
9 description="A Python shell. Use this to execute python commands. Input should be a valid python command. If you want to see the output of a value, you should print it out with `print(...)`.",
10 func=python_repl.run,
11)
12repl_tool(outputs[0]["generated_text"][-1])