this post was submitted on 01 Jul 2023
6 points (100.0% liked)

Actually Useful AI

2010 readers
7 users here now

Welcome! ๐Ÿค–

Our community focuses on programming-oriented, hype-free discussion of Artificial Intelligence (AI) topics. We aim to curate content that truly contributes to the understanding and practical application of AI, making it, as the name suggests, "actually useful" for developers and enthusiasts alike.

Be an active member! ๐Ÿ””

We highly value participation in our community. Whether it's asking questions, sharing insights, or sparking new discussions, your engagement helps us all grow.

What can I post? ๐Ÿ“

In general, anything related to AI is acceptable. However, we encourage you to strive for high-quality content.

What is not allowed? ๐Ÿšซ

General Rules ๐Ÿ“œ

Members are expected to engage in on-topic discussions, and exhibit mature, respectful behavior. Those who fail to uphold these standards may find their posts or comments removed, with repeat offenders potentially facing a permanent ban.

While we appreciate focus, a little humor and off-topic banter, when tasteful and relevant, can also add flavor to our discussions.

Related Communities ๐ŸŒ

General

Chat

Image

Open Source

Please message @[email protected] if you would like us to add a community to this list.

Icon base by Lord Berandas under CC BY 3.0 with modifications to add a gradient

founded 1 year ago
MODERATORS
all 3 comments
sorted by: hot top controversial new old
[โ€“] sisyphean 2 points 1 year ago* (last edited 1 year ago) (1 children)

This is a very useful trick, but since the June update you can also use the "function calling" feature to extract structured data. I converted the example in the blog post (I used GPT-4 to convert the TypeScript type into a JSON schema):

curl https://api.openai.com/v1/chat/completions -u :$OPENAI_API_KEY -H 'Content-Type: application/json' -d '{
  "model": "gpt-3.5-turbo-0613",
  "messages": [
    {"role": "user", "content": "A user has performed the following searches and visited the following sites recently: weather in New York, NYC weather, NYC chance of rain today, is New York a rainy city (They may or may not have changed goals half way through this session.)"}
  ],
  "functions": [
    {
      "name": "report_browsing_goal_analysis",
      "description": "Reports the analysis the users recent browsing activity",
      "parameters": {
        "type": "object",
        "properties": {
            "goal": {
                "type": "string",
                "description": "The users consistent recent browsing goal"
            },
            "confidence": {
                "type": "string",
                "description": "How confident the analysis engine is in this goal",
                "enum": ["very low", "low", "med", "high", "very high"]
            },
            "switched": {
                "type": "boolean",
                "description": "Whether or not the user seems to have switched goals recently"
            },
            "advice": {
                "type": "array",
                "description": "An array of up to 3 creative, specific, non-obvious ways the system recommends for the user to meet their current goal. (Do not return generic suggestions like subscribe to a newsletter or do a Google search, instead recommend specific actions that the user should consider.)",
                "items": {
                    "type": "object",
                    "properties": {
                        "text": {
                            "type": "string"
                        },
                        "probabilityOfBeingUseful": {
                            "type": "string",
                            "enum": ["very low", "low", "med", "high", "very high"]
                        },
                        "creativity": {
                            "type": "string",
                            "enum": ["very low", "low", "med", "high", "very high"]
                        },
                        "funLevel": {
                            "type": "string",
                            "enum": ["very low", "low", "med", "high", "very high"]
                        }
                    },
                    "required": ["text", "probabilityOfBeingUseful", "creativity", "funLevel"]
                },
                "maxItems": 3
            }
        },
        "required": ["goal", "confidence", "switched", "advice"]
    }
    }
  ]
}'

This is what the API returned:

{
  "id": "chatcmpl-7Xd4BPsW9QBuk46BJRZRCNoFpJtV9",
  "object": "chat.completion",
  "created": 1688249351,
  "model": "gpt-3.5-turbo-0613",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": null,
        "function_call": {
          "name": "report_browsing_goal_analysis",
          "arguments": "{\n  \"goal\": \"weather in New York\",\n  \"confidence\": \"high\",\n  \"switched\": false,\n  \"advice\": [\n    {\n      \"text\": \"Check the hourly weather forecast for New York to plan your activities.\",\n      \"probabilityOfBeingUseful\": \"high\",\n      \"creativity\": \"high\",\n      \"funLevel\": \"low\"\n    },\n    {\n      \"text\": \"Subscribe to a weather alert service to stay updated on the weather in New York.\",\n      \"probabilityOfBeingUseful\": \"medium\",\n      \"creativity\": \"medium\",\n      \"funLevel\": \"low\"\n    },\n    {\n      \"text\": \"Join a local weather enthusiasts group to discuss weather patterns in New York.\",\n      \"probabilityOfBeingUseful\": \"low\",\n      \"creativity\": \"high\",\n      \"funLevel\": \"high\"\n    }\n  ]\n}"
        }
      },
      "finish_reason": "function_call"
    }
  ],
  "usage": {
    "prompt_tokens": 303,
    "completion_tokens": 194,
    "total_tokens": 497
  }
}

Here is just the JSON result extracted:

{
  "goal": "weather in New York",
  "confidence": "high",
  "switched": false,
  "advice": [
    {
      "text": "Check the hourly weather forecast for New York to plan your activities.",
      "probabilityOfBeingUseful": "high",
      "creativity": "high",
      "funLevel": "low"
    },
    {
      "text": "Subscribe to a weather alert service to stay updated on the weather in New York.",
      "probabilityOfBeingUseful": "medium",
      "creativity": "medium",
      "funLevel": "low"
    },
    {
      "text": "Join a local weather enthusiasts group to discuss weather patterns in New York.",
      "probabilityOfBeingUseful": "low",
      "creativity": "high",
      "funLevel": "high"
    }
  ]
}

Pretty cool, isn't it?

(BTW this was GPT-3.5)

[โ€“] tectonic 2 points 1 year ago