Closed jravenel closed 1 year ago
The goal of the driver is to be able to generate plugin with a function. It also should be able to count the number of tokens depending on the model used.
Here's how you can wrap the given Python code in a function with a docstring:
import json
import tiktoken
import naas
def num_tokens_from_string(string: str, encoding_name: str) -> int:
"""Returns the number of tokens in a text string."""
encoding = tiktoken.get_encoding(encoding_name)
num_tokens = len(encoding.encode(string))
return num_tokens
def create_plugin(
name,
prompt,
model="gpt-3.5-turbo-16k",
temperature=0,
output_path=None,
):
# Create output
if not output_path:
output_path= plugin_name.lower().replace(" ", "_") + "_plugin.json"
# Get max tokens (dict to be stored in driver with key as model, value as int)
# Check tokens
# Create json
plugin = {
"name": name,
"model": model,
"temperature": temperature,
"max_tokens": plugin_max_tokens,
"prompt": prompt,
}
# Save dict to JSON file
with open(output_path, "w") as f:
json.dump(plugin, f)
# Create asset
print("💾 Plugin successfully saved. You can use it in your Naas Chat with:", asset_link)
return asset_link
@Dr0p42, as we are developing more plugins I would like to create simple driver to start. Do you think I could implement the code above?
Can you review the parameters of the function and let me know if I miss something?
@FlorentLvr can you specify following what we discussed today during the community call?