<type>documentation</type>
<domain>ai</domain>
<id>ai</id>
<title>AI Quick Start Guide</title>
<date>$Date: 2006-05-24 22:53:07 -0400 (Wed, 24 May 2006) $</date>
<version>$Revision: 13098 $</version>
<product>pro+</product>

Wing's AI assisted development features work with OpenAI, Gemini, Grok, Perplexity, Claude,
Mistral, Deepseek, and any other AI provider that implements an OpenAI compatible AI completions API.

Before you can use AI assisted development, you will need to obtain an API key directly from your
selected AI provider. Depending on the AI provider that you choose, you may see substantially
different results if you use newer AI models, but you may not be able to access those or they may be
rate limited unless you pay a certain amount into your account to start with. The limitations and
models available change constantly over time, as does pricing. In general, using the very latest
models is very expensive, and using slightly older models is very inexpensive, or in some cases
free.

**Configuration**

Once you have your AI provider API key, select ``Manage AI Providers`` from the ``AI`` menu in Wing
Pro and press the ``+`` icon to add a new provider. Give the provider a name and select the API host
to use (either one of the supported providers or a custom URL). 

Then either paste the API key in under the ``Use Key`` option or place it into a file, either at the
default location given in the dialog or anywhere else on disk. Using the default key file location
is generally easier since you may want multiple configurations, for example to use different models.

You will also need to enter the AI model you want to use and should adjust the per-token costs if
you want to see accurate cost estimates as you make requests from Wing.

Note that by default your provider configuration is stored in the current project and won't be
accessible in other projects.  You can indicate a provider configuration should be shared among all 
projects from the ``Manage AI Providers`` dialog.

For details on configuring AI assisted development in Wing, see `Configuring AI Providers
<ref:ai/provider>`__.

**AI Chat**

Next test the integration by selecting ``Show AI Chat`` from the ``AI`` menu and entering "Create a
Python hello world" into the ``AI Chat`` tool. When you press ``Enter``, Wing will ask you to
approve uploading data to the AI provider. This approval is needed on a per-project basis, to make
sure that your instructions and the code in that project may be uploaded to the AI service. If you
refuse to upload data, the integration will refuse to submit anything to the AI provider. Otherwise,
your request will be processed after you approve uploads, and you should see the result appear in
the ``AI Chat`` tool.

``AI Chat`` cannot directly alter code in your editors, but you can use the floating icons next to
any code in the tool to either copy that code to the clipboard or paste it directly into the current
editor.

The ``AI Chat`` tool is most useful for asking about existing code and iteratively exploring design
and implementation ideas.

See `AI Chat Assistant <ref:ai/chat>`__ for details.

**AI Coder**

To work directly on code in the editor, select ``Show AI Coder`` from the ``AI`` menu.  This tool
can carry out a wide variety of coding requests, from writing new code to extending or rewriting
existing code.  It can make changes directly in the editor, either immediately or through a change
review and approval process.

The ``Target`` in the tool identifies which code you are asking AI to work on.  Only that code
will be changed by the request that you enter here.

The ``Action`` menu lets you specify how the resulting code should be applied:  Either by 
replacing the target or creating a new file.  When replacing code, you may opt to overwrite it,
leave old code in commented out form, or start a review process with the default of either
approving or rejecting changes.

The ``Requests`` menu lets you save named requests for future reuse.  Wing comes with a set of
example requests for tasks like writing unit tests, generating documentation, rewriting code
to be asynchonous, and running a security review.  You can modify these or add your own 
requests.

Note that one request is always current, and editing the text in the ``AI Coder`` tool's request
area will alter that saved request.

Requests can be set up to specify the action they take, for example replacing existing code,
creating a new file, or running the request in ``AI Chat``.

From the requests manager dialog accessed by ``Manage Saved Requests`` in the ``Requests`` menu, you
may also indicate that a request can be shared by all projects, and requests may be assigned a key
binding, including multi-key bindings like ``Ctrl-A Ctrl-D``, so that you can easily invoke them.

In general, ``AI Coder`` is the most powerful way to do actual coding with AI, whether writing new
code or extending or rewriting existing code.

See `AI Coder Tool <ref:ai/coder>`__ for details.

**AI Suggest**

Wing can also use AI to write code at the current editor insertion point without any additional
description of the code that should be added. This is done by pressing ``Ctrl-?`` (repeatedly if you
don't like the first suggestion) and then either accepting a suggestion with ``Enter`` or rejecting
it with ``Esc``. 

Although AI Suggest can be useful when the code needed is obvious from local context, it
is often far less effective at producing useful results than the ``AI Coder`` tool.

See `AI Suggested Code Completion <ref:ai/suggest>`__ for details.

**Request Context**

You can independently select additional context for AI requests from the ``Context`` menu in the
``AI Chat`` and ``AI Coder`` tools, and from ``AI Suggestion Context`` in the ``AI`` menu. Context
may automatically include imported and other files depending on your focus, or you can select and
describe specific files or sections of code.

For example, you might select some existing code and describe it as "an example of the kind of
dialog I want", you can add a file that contains your coding conventions and describe it as "these
are the coding conventions to use", and you could add another file or selection range described as
"this is the API I want the implementation to use".

Your context options are stored and used until you change them, and you may create and save
multiple named contexts that can be reused in ``AI Chat``, with each stored request in ``AI Coder``,
and for ``AI Suggest``.

As for requests, you can share saved contexts between all your projects from the ``Manage Saved
Contexts`` item in the ``Context`` menu.

See `AI Request Context <ref:ai/context>`__ for details.

**Best Practices**

The key to using AI assisted development effectively is to right-size the requests that you make,
and to ensure that the AI has all the instructions and context it will need to carry out its task
in the way that you want it to. AI doesn't replace you, but rather acts as a very capable assistant
that you manage through the completion of a series of tasks. See `Improving Results
Obtained from AI Assisted Development <ref:ai/tips>`__ for details.

As long as you are not using the very latest AI models, which can be quite expensive, you should
find that your day-to-day costs for using AI assisted development are very low, or even zero if you
are using an AI provider that allows personal use for free. 

If you are using a paid service and have set the per-token costs correctly in your AI provider
configuration, then you can track the approximate costs of your requests at the bottom of the ``AI
Chat`` and ``AI Coder`` tools. Check your AI provider account for the exact amounts that you are
being charged. See `Managing Cost <ref:ai/cost>`__ for details.

