simonw / llm-anyscale-endpoints

LLM plugin for models hosted by Anyscale Endpoints
Apache License 2.0
32 stars 4 forks source link

codellama/CodeLlama-34b-Instruct-hf #2

Closed simonw closed 1 year ago

simonw commented 1 year ago

Code Llama is now available as codellama/CodeLlama-34b-Instruct-hf

It looks like you can't link directly to the documentation page, so here's a screenshot:

Supported models > codellama/CodeLlama-34b-Instruct-hf codellama/CodeLlama-34b-Instruct-hf © INFO Refer to the Hugging Face model page for more model details. About this model Model name to use in API calls: codellama/CodeLlama-34b-Instruct-hf Code Llama is a collection of pretrained and fine-tuned generative text models ranging in scale from 7 billion to 34 billion parameters. This is the 34B parameter version, fine tuned for instructions. This model is designed for general code synthesis and understanding. Links to other models can be found in the index at the bottom.
simonw commented 1 year ago

Got this out of it - not too impressed by the answers to the follow-ups, it seemed to forget its previous context a tiny bit:


2023-08-25T11:16:13 conversation: 01h8p6hrdy330z9x8pmknda114

Model: codellama/CodeLlama-34b-Instruct-hf

Prompt:

Python code to download a CSV from a URL and create a SQLite database table matching its schema and insert the data

Response:

To download a CSV file from a URL and create a SQLite database table matching its schema and insert the data, you can use the following Python code:

import csv
import sqlite3

# URL of the CSV file
url = "https://example.com/data.csv"

# Connect to the SQLite database
conn = sqlite3.connect("data.db")

# Create a cursor object
cur = conn.cursor()

# Download the CSV file
with open(url, "r") as f:
    reader = csv.reader(f)
    headers = next(reader)
    data = [row for row in reader]

# Create a table in the SQLite database
cur.execute("CREATE TABLE data (id INTEGER PRIMARY KEY, {})".format(", ".join(headers)))

# Insert the data into the table
for row in data:
    cur.execute("INSERT INTO data VALUES ({})".format(", ".join(row)))

# Commit the changes
conn.commit()

# Close the cursor and connection
cur.close()
conn.close()

This code will download the CSV file from the specified URL, create a SQLite database table with the same schema as the CSV file, and insert the data into the table.

It's important to note that this code assumes that the CSV file has a header row, and that the header row contains the column names that should be used for the SQLite table. If the CSV file does not have a header row, or if the header row contains different column names, you will need to modify the code accordingly.

Also, this code uses the sqlite3 module to connect to the SQLite database, so you will need to have the sqlite3 module installed on your system in order to use this code.

2023-08-25T11:16:54 conversation: 01h8p6hrdy330z9x8pmknda114

Model: codellama/CodeLlama-34b-Instruct-hf

Prompt:

Make sure the columns are created with type text

Response:

To create columns with type text in SQLite, you can use the TEXT data type. Here's an example of how to create a table with a text column in SQLite:

CREATE TABLE mytable (
    id INTEGER PRIMARY KEY,
    name TEXT,
    description TEXT
);

In this example, the name and description columns are created with the TEXT data type, which allows you to store text data in those columns.

You can also specify the length of the text column by adding a number in parentheses after the TEXT keyword. For example:

CREATE TABLE mytable (
    id INTEGER PRIMARY KEY,
    name TEXT(20),
    description TEXT(100)
);

In this example, the name column is limited to 20 characters, and the description column is limited to 100 characters.

It's important to note that the TEXT data type in SQLite is not the same as the VARCHAR data type in other databases. In SQLite, TEXT is a variable-length data type, which means that it can store strings of any length. In contrast, VARCHAR is a fixed-length data type, which means that it can only store strings of a specific length.

2023-08-25T11:17:19 conversation: 01h8p6hrdy330z9x8pmknda114

Model: codellama/CodeLlama-34b-Instruct-hf

Prompt:

rewrite the original code to do that

Response:

Here is an example of how you can modify the original code to use the requests library to make a GET request to the API and retrieve the data:

import requests

# Set the API endpoint URL
url = "https://api.example.com/data"

# Set the headers
headers = {
    "Authorization": "Bearer your_access_token",
    "Content-Type": "application/json"
}

# Make the GET request
response = requests.get(url, headers=headers)

# Check the response status code
if response.status_code == 200:
    # Parse the JSON data
    data = response.json()

    # Print the data
    print(data)
else:
    print("Error:", response.status_code)

This code makes a GET request to the API endpoint and retrieves the data in JSON format. It then parses the JSON data and prints it to the console.

You can also use the requests library to make other types of requests, such as POST, PUT, and DELETE. For example:

# Make a POST request
response = requests.post(url, headers=headers, data=data)

# Make a PUT request
response = requests.put(url, headers=headers, data=data)

# Make a DELETE request
response = requests.delete(url, headers=headers)

You can also use the requests library to handle errors and exceptions, such as connection errors and timeouts. For example:

try:
    # Make the request
    response = requests.get(url, headers=headers)
except requests.exceptions.ConnectionError:
    print("Error: Connection error")
except requests.exceptions.Timeout:
    print("Error: Timeout")

This code tries to make the request, but if it encounters a connection error or a timeout, it prints an error message to the console.