Skip to content

4munix/vim-xai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

vim-xai.pl - A Perl script for interacting with Grok AI completion service

SYNOPSIS

use LWP::UserAgent;
use HTTP::Request;
use JSON;
use utf8;
use open ':std', ':encoding(UTF-8)';

main();

DESCRIPTION

This script is designed to interact with an AI completion service, for use within a Vim plugin. It sends a request to an AI service with user-defined parameters and processes the streaming response to update the Vim buffer in real-time.

TEASER

FUNCTIONS

main()

The main function orchestrates the script's operation:

  • Evaluates Vim variables for configuration.

  • Prepares and sends an HTTP POST request to the AI service.

  • Handles the response, either streaming or non-streaming, and updates the Vim buffer accordingly.

do_msg($chunk)

Processes chunks of the streaming response:

  • Accumulates chunks until a complete message is received.

  • Decodes JSON from the message chunks.

  • Updates the Vim buffer with the AI's response content.

  • Ensures immediate output by setting autoflush.

VARIABLES

$chunk_buffer

Stores incomplete chunks of the streaming response.

$collect_messages

Accumulates the content of the AI's response for display.

@evals

An array of Vim variables to evaluate for configuration.

$xai_xd_obj

A JSON object representing the request to the AI service.

$json_string

The JSON encoded string of the request object.

$headers

HTTP headers for the request, including authentication.

$ua

An instance of LWP::UserAgent for making HTTP requests.

$req

The HTTP request object.

$response

The HTTP response object from the AI service.

DEPENDENCIES

  • LWP::UserAgent

  • HTTP::Request

  • JSON

  • utf8

  • open

AUTHOR

Albert Mendes <tray.mendes@gmail.com>

SEE ALSO

Vim, Perl, JSON, LWP::UserAgent

About

vim plugin for x.ai

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors