microsoft / Phi-3CookBook

This is a Phi-3 book for getting started with Phi-3. Phi-3, a family of open AI models developed by Microsoft. Phi-3 models are the most capable and cost-effective small language models (SLMs) available, outperforming models of the same size and next size up across a variety of language, reasoning, coding, and math benchmarks.
MIT License
2.24k stars 224 forks source link

Using planner with phi 3 vision #139

Closed Barshan-Mandal closed 1 month ago

Barshan-Mandal commented 1 month ago

How to use planner with phi 3 vision.Give an code example in c#.

sorry to bother you.I am new is this arena

leestott commented 1 month ago

Here's a simple example of how you can use the Phi-3 Vision model with a planner in C#:

  1. Install the necessary packages:

    • Ensure you have the required packages installed. You might need to use NuGet to install any missing dependencies.
  2. Code Example:

Code Explanation:

  1. Imports:

    • System, System.IO, System.Net.Http, and System.Threading.Tasks are used for basic operations and HTTP requests.
    • Newtonsoft.Json.Linq is used for handling JSON responses.
  2. Main Method:

    • Load the Image: Reads the image file into a byte array.
    • Prepare the Request: Creates an HTTP client and prepares a multipart form data request with the image.
    • Send the Request: Sends the request to the model's API endpoint.
    • Process the Response: Parses the JSON response and extracts the generated caption.
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

class Program
{
    static async Task Main(string[] args)
    {
        string modelId = "microsoft/Phi-3-vision-128k-instruct";
        string outDir = "model/phi3-vision/int4";
        string imagePath = "./imgs/demo.png";

        // Load the image
        byte[] imageBytes = File.ReadAllBytes(imagePath);

        // Prepare the request
        var client = new HttpClient();
        var requestContent = new MultipartFormDataContent();
        requestContent.Add(new ByteArrayContent(imageBytes), "file", "demo.png");

        // Send the request to the model
        var response = await client.PostAsync($"https://api.example.com/models/{modelId}/predict", requestContent);
        response.EnsureSuccessStatusCode();

        // Process the response
        var responseContent = await response.Content.ReadAsStringAsync();
        var jsonResponse = JObject.Parse(responseContent);

        // Output the result
        Console.WriteLine("Generated Caption: " + jsonResponse["caption"]);
    }
}

Note This example assumes you have an API endpoint for the Phi-3 Vision model. You might need to adjust the URL and other details based on your specific setup.

Barshan-Mandal commented 4 days ago

what about offline planning