Skip to content

Instantly share code, notes, and snippets.

@bernadinm
Last active December 3, 2023 01:44
Show Gist options
  • Save bernadinm/5d1ae8c85dc3ce2b0ddbfc7e82c92165 to your computer and use it in GitHub Desktop.
Save bernadinm/5d1ae8c85dc3ce2b0ddbfc7e82c92165 to your computer and use it in GitHub Desktop.
Hello Pulze.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"name": "Hello Pulze.ipynb",
"authorship_tag": "ABX9TyOGNmbmE8f0dbmbraFgeaOr",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/bernadinm/5d1ae8c85dc3ce2b0ddbfc7e82c92165/untitled0.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "YfjzRcTAmWAL",
"outputId": "9d5aa58e-0423-4c42-fdd5-7fa2fb654094"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]\n"
]
}
],
"source": [
"import sys\n",
"print(sys.version)"
]
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"id": "OfoFNxFznddA"
}
},
{
"cell_type": "code",
"source": [
"print(\"Hello Pulze!\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "0z9ivEC9ndzN",
"outputId": "a92bbbfb-c3f1-4da0-df96-a86abfee27b0"
},
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Hello Pulze!\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"!pip install openai==0.28.0"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "fkPm4LPlq4aD",
"outputId": "481d9dba-e4b0-4dcc-89c1-62398c7417bf"
},
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Collecting openai==0.28.0\n",
" Downloading openai-0.28.0-py3-none-any.whl (76 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m76.5/76.5 kB\u001b[0m \u001b[31m823.2 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: requests>=2.20 in /usr/local/lib/python3.10/dist-packages (from openai==0.28.0) (2.31.0)\n",
"Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from openai==0.28.0) (4.66.1)\n",
"Requirement already satisfied: aiohttp in /usr/local/lib/python3.10/dist-packages (from openai==0.28.0) (3.9.1)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai==0.28.0) (3.3.2)\n",
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai==0.28.0) (3.6)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai==0.28.0) (2.0.7)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai==0.28.0) (2023.11.17)\n",
"Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai==0.28.0) (23.1.0)\n",
"Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai==0.28.0) (6.0.4)\n",
"Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai==0.28.0) (1.9.3)\n",
"Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai==0.28.0) (1.4.0)\n",
"Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai==0.28.0) (1.3.1)\n",
"Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai==0.28.0) (4.0.3)\n",
"Installing collected packages: openai\n",
"\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
"llmx 0.0.15a0 requires cohere, which is not installed.\n",
"llmx 0.0.15a0 requires tiktoken, which is not installed.\u001b[0m\u001b[31m\n",
"\u001b[0mSuccessfully installed openai-0.28.0\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"import json\n",
"import openai"
],
"metadata": {
"id": "iKKmAoMApVjG"
},
"execution_count": 4,
"outputs": []
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"id": "QYHGUrW7pZ_X"
}
},
{
"cell_type": "code",
"source": [
"from getpass import getpass\n",
"openai.api_key = getpass('Enter your Pulze API Key: ') # Supply your key however you choose\n",
"openai.api_base = \"https://api.pulze.ai/v1\" # Enter Pulze's URL"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "zgk8lk0jpbNr",
"outputId": "e3f870f3-2467-4b52-8a35-5821f4a90905"
},
"execution_count": 5,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter your Pulze API Key: ··········\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Set up your custom labels and weights\n",
"headers = {\n",
" \"Pulze-Labels\": json.dumps({\"foo\": \"bar\", \"group\": \"standard\"}),\n",
" \"Pulze-Weights\": json.dumps({\"cost\": 0.5, \"quality\": 0.5, \"latency\": 0}),\n",
"}\n",
"\n",
"text_response = openai.Completion.create(\n",
" model=\"pulze-v0\",\n",
" prompt=\"Say Hello World!\",\n",
" headers=headers,\n",
")\n",
"\n",
"chat_response = openai.ChatCompletion.create(\n",
" model=\"pulze-v0\",\n",
" messages=[{\n",
" \"role\": \"user\",\n",
" \"content\": \"Say Hello World!\"\n",
" }],\n",
" headers=headers,\n",
")\n",
"\n"
],
"metadata": {
"id": "p7cS58HRqFXc"
},
"execution_count": 6,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Print the results from Pulze"
],
"metadata": {
"id": "4od5Ul-tpfgv"
}
},
{
"cell_type": "code",
"source": [
"print(text_response, chat_response)"
],
"metadata": {
"id": "FOiUPFvkpbVI",
"outputId": "b69fb043-0577-4c34-f804-6ed84c234798",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 7,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"{\n",
" \"choices\": [\n",
" {\n",
" \"index\": 0,\n",
" \"text\": \"Hello World!\"\n",
" }\n",
" ],\n",
" \"created\": 1701473254883,\n",
" \"metadata\": {\n",
" \"app_id\": \"798f1b06-18fa-4539-866b-9077b2b5cbe2\",\n",
" \"model\": {\n",
" \"model\": \"gpt-3.5-turbo\",\n",
" \"provider\": \"openai\",\n",
" \"namespace\": \"openai/gpt-3.5-turbo\"\n",
" },\n",
" \"costs\": {\n",
" \"total_tokens\": 1.7e-05,\n",
" \"prompt_tokens\": 1.1e-05,\n",
" \"completion_tokens\": 6e-06\n",
" },\n",
" \"cost_savings\": {\n",
" \"total_tokens\": 0.000823,\n",
" \"prompt_tokens\": 0.000649,\n",
" \"completion_tokens\": 0.000174\n",
" },\n",
" \"latency\": 0.387,\n",
" \"category\": \"Arts & Crafts\",\n",
" \"labels\": {\n",
" \"foo\": \"bar\",\n",
" \"group\": \"standard\",\n",
" \"weights_cost\": \"0.5\",\n",
" \"weights_latency\": \"0.0\",\n",
" \"weights_quality\": \"0.5\"\n",
" },\n",
" \"scores\": {\n",
" \"best_models\": [\n",
" {\n",
" \"openai/gpt-3.5-turbo\": 0.989\n",
" },\n",
" {\n",
" \"openai/text-curie-001\": 0.949\n",
" },\n",
" {\n",
" \"anthropic/claude-instant-v1\": 0.937\n",
" },\n",
" {\n",
" \"ai21labs/j2-light\": 0.925\n",
" },\n",
" {\n",
" \"mosaicml/llama2-70b-chat\": 0.902\n",
" }\n",
" ]\n",
" },\n",
" \"score\": 0.9885377457130907,\n",
" \"temperature\": 1.0,\n",
" \"status_code\": 200\n",
" },\n",
" \"id\": \"51e436d1-8ef8-48a1-a318-52fdfe5f9520\",\n",
" \"usage\": {\n",
" \"total_tokens\": 14.0,\n",
" \"prompt_tokens\": 11.0,\n",
" \"completion_tokens\": 3.0\n",
" },\n",
" \"model\": \"openai/gpt-3.5-turbo\",\n",
" \"object\": \"text_completion\"\n",
"} {\n",
" \"choices\": [\n",
" {\n",
" \"index\": 0,\n",
" \"message\": {\n",
" \"role\": \"assistant\",\n",
" \"content\": \"Hello World!\"\n",
" }\n",
" }\n",
" ],\n",
" \"created\": 1701473255606,\n",
" \"metadata\": {\n",
" \"app_id\": \"798f1b06-18fa-4539-866b-9077b2b5cbe2\",\n",
" \"model\": {\n",
" \"model\": \"gpt-3.5-turbo\",\n",
" \"provider\": \"openai\",\n",
" \"namespace\": \"openai/gpt-3.5-turbo\"\n",
" },\n",
" \"costs\": {\n",
" \"total_tokens\": 1.7e-05,\n",
" \"prompt_tokens\": 1.1e-05,\n",
" \"completion_tokens\": 6e-06\n",
" },\n",
" \"cost_savings\": {\n",
" \"total_tokens\": 0.000823,\n",
" \"prompt_tokens\": 0.000649,\n",
" \"completion_tokens\": 0.000174\n",
" },\n",
" \"latency\": 0.554,\n",
" \"category\": \"Books & Literature\",\n",
" \"labels\": {\n",
" \"foo\": \"bar\",\n",
" \"group\": \"standard\",\n",
" \"weights_cost\": \"0.5\",\n",
" \"weights_latency\": \"0.0\",\n",
" \"weights_quality\": \"0.5\"\n",
" },\n",
" \"scores\": {\n",
" \"best_models\": [\n",
" {\n",
" \"openai/gpt-3.5-turbo\": 0.962\n",
" },\n",
" {\n",
" \"openai/text-curie-001\": 0.947\n",
" },\n",
" {\n",
" \"mosaicml/llama2-70b-chat\": 0.935\n",
" },\n",
" {\n",
" \"anthropic/claude-instant-v1\": 0.928\n",
" },\n",
" {\n",
" \"openai/text-babbage-001\": 0.891\n",
" }\n",
" ]\n",
" },\n",
" \"score\": 0.9618055555555554,\n",
" \"temperature\": 1.0,\n",
" \"status_code\": 200\n",
" },\n",
" \"id\": \"346cff9f-a1a7-4c24-bdd4-10545ea2df10\",\n",
" \"usage\": {\n",
" \"total_tokens\": 14.0,\n",
" \"prompt_tokens\": 11.0,\n",
" \"completion_tokens\": 3.0\n",
" },\n",
" \"model\": \"openai/gpt-3.5-turbo\",\n",
" \"object\": \"chat.completion\"\n",
"}\n"
]
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment