儘管美國的外交作為內含一種「美國式的危機管理哲學」,也就是美國國安顧問蘇利文與副國務卿坎貝爾2019年在《外交事務》(Foreign
Affairs) 期刊中講的一句「畫龍點睛」的關鍵詞:「競爭但不惹禍」(competition without
catastrophe),認為通過風險管理可以營造公平競爭的環境。但是,當前美中之間的競爭已經結束,迎來的是對抗。
Since the SOCKS proxy performs at Layer 5 of the OSI model (the session layer), you may use it with many applications that work in a Layer higher than Layer 5, such as FTP, Telnet, HTTP, SSH…
SSH via SOCKS proxy
For example, if you want to SSH to a Far_Away_Host via the SOCKS proxy we just created. You can do:
After
login into the Far_Away_Host, you can check that you are deemed as
connected from SSH_remote_host_IP instead of your local machine!
username@Far_Away_Host$ who username pts/3 2021-03-29 14:08 (SSH_remote_host_IP)
FTP via SOCKS proxy
Another example is the SOCKS proxy setting in FileZilla, an FTP client:
Further Reading
There is a convenient tool — sshuttle suggested by smw on Hacker News. It works as a poor man’s VPN using ssh, which also doesn’t require admin on the remote machine. The manual is here. It can be easily installed on, e.g., macOS and Ubuntu via:
# on Ubuntu $ sudo apt install sshuttle# on macOS, installed by macports $ sudo port install sshuttle
Add dependencies for the specific AI model, Vector Database or other component dependencies you require.
Overview
Despite
the extensive history of AI, Java's role in this domain has been
relatively minor.
This is mainly due to the historical reliance on efficient algorithms
developed in languages such as C/C++, with Python serving as a bridge to
access these libraries.
The majority of ML/AI tools were built around the Python ecosystem.
However, recent progress in Generative AI, spurred by innovations like
OpenAI's ChatGPT, has popularized the interaction with pre-trained
models via HTTP.
This eliminates much of the dependency on C/C++/Python libraries and
opens the door to the use of programming languages such as Java.
The Python libraries LangChain and LlamaIndex have become popular to implement Generative AI solutions and can be implemented in other programming languages.
These Python libraries share foundational themes with Spring projects, such as:
Portable Service Abstractions
Modularity
Extensibility
Reduction of boilerplate code
Integration with diverse data sources
Prebuilt solutions for common use cases
Taking inspiration from these libraries, the Spring AI
project aims to provide a similar experience for Spring developers in
the AI domain.
Note, that the Spring AI API is not a direct port of
either LangChain or LlamaIndex. You will see significant differences in
the API if you are familiar with those two projects, though concepts
and ideas are fairly portable.
Feature Overview
This is a high level feature overview.
The features that are implemented lay the foundation, with subsequent more complex features building upon them.
ChatClient:
A foundational feature of Spring AI is a portable client API for
interacting with generative AI models. With this portable API, you can
initially target one AI chat model, for example OpenAI and then easily
swap out the implementation to another AI chat model, for example Amazon
Bedrock's Anthropic Model. When necessary, you can also drop down to
use non-portable model options.
Spring AI supports many AI models. For an overview see here. Specific models currently supported are
Prompts: Central to AI model interaction is the Prompt, which provides specific instructions for the AI to act upon.
Crafting an effective Prompt is both an art and science, giving rise to the discipline of "Prompt Engineering".
These prompts often leverage a templating engine for easy data substitution within predefined text using placeholders.
Explore more on Prompts in our concept guide.
To learn about the Prompt class, refer to the Prompt API guide.
Prompt Templates: Prompt Templates support the creation of prompts, particularly when a Template Engine is employed.
Output Parsers: AI model outputs often come as raw java.lang.String values. Output Parsers restructure these raw strings into more programmer-friendly formats, such as CSV or JSON.
Incorporating
proprietary data into Generative AI without retraining the model has
been a breakthrough.
Retraining models, especially those with billions of parameters, is
challenging due to the specialized hardware required.
The 'In-context' learning technique provides a simpler method to infuse
your pre-trained model with data, whether from text files, HTML, or
database results.
The right techniques are critical for developing successful solutions.
Retrieval Augmented Generation
Retrieval Augmented Generation, or RAG for short, is a pattern that enables you to bring your data to pre-trained models.
RAG excels in the 'query over your docs' use-case.
Bringing your data to the model follows an Extract, Transform, and Load (ETL) pattern.
The subsequent classes and interfaces support RAG's data preparation.
Documents:
The Document class encapsulates your data, including text and metadata, for the AI model.
While a Document can represent extensive content, such as an entire file, the RAG approach
segments content into smaller pieces for inclusion in the prompt.
The ETL process uses the interfaces DocumentReader, DocumentTransformer, and DocumentWriter, ending with data storage in a Vector Database.
This database later discerns the pieces of data that are pertinent to a user's query.
Document Readers:
Document Readers produce a List<Document>
from diverse sources like PDFs, Markdown files, and Word documents.
Given that many sources are unstructured, Document Readers often segment
based on content semantics, avoiding splits within tables or code
sections.
After the initial creation of the List<Document>, the data flows through transformers for further refinement.
Document Transformers:
Transformers further modify the List<Document>
by eliminating superfluous data, like PDF margins, or appending
metadata (e.g., primary keywords or summaries).
Another critical transformation is subdividing documents to fit within
the AI model's token constraints.
Each model has a context-window indicating its input and output data
limits. Typically, one token equates to about 0.75 words. For instance,
in model names like gpt-4-32k, "32K" signifies the token count.
Document Writers:
The final ETL step within RAG involves committing the data segments to a Vector Database.
Though the DocumentWriter interface isn't exclusively for Vector Database writing, it the main type of implementation.
Vector Stores: Vector Databases are instrumental in incorporating your data with AI models.
They ascertain which document sections the AI should use for generating responses.
Examples of Vector Databases include Chroma, Postgres, Pinecone, Qdrant, Weaviate, Mongo Atlas, and Redis. Spring AI's VectorStore abstraction permits effortless transitions between database implementations.
Cloning the repo
This repository contains large model files.
To clone it you have to either:
Ignore the large files (won't affect the spring-ai behaviour) : GIT_LFS_SKIP_SMUDGE=1 git clone git@github.com:spring-projects/spring-ai.git.
This section offers jumping off points for how to get started using Spring AI.
You should follow the steps in each of the following section according to your needs.
Spring CLI
The Spring CLI, simplifies creating new applications directly from your terminal.
Like the 'create-react-app' command for those familiar with the JavaScript ecosystem, Spring CLI provides a spring boot new
command to create Spring-based projects.
Spring CLI also offers features to integrate external code bases into
your current project, and many other productivity features.
It is important to understand that the "Spring CLI" is a distinct
project from the "Spring Boot CLI", each with its own set of
functionalities.
To begin creating a Spring AI application, follow these steps:
The Spring AI Bill of Materials (BOM) declares the recommended
versions of all the dependencies used by a given release of Spring AI.
Using the BOM from your application’s build script avoids the need for
you to specify and maintain the dependency versions yourself.
Instead, the version of the BOM you’re using determines the utilized
dependency versions.
It also ensures that you’re using supported and tested versions of the
dependencies by default, unless you choose to override them.
If you’re a Maven user, you can use the BOM by adding the following to your pom.xml file -
Gradle users can also use the Spring AI BOM by leveraging Gradle
(5.0+) native support for declaring dependency constraints using a Maven
BOM.
This is implemented by adding a 'platform' dependency handler method to
the dependencies section of your Gradle build script.
As shown in the snippet below this can then be followed by version-less
declarations of the Starter Dependencies for the one or more spring-ai
modules you wish to use, e.g. spring-ai-openai.
dependencies {
implementation platform("org.springframework.ai:spring-ai-bom:0.8.1-SNAPSHOT")
// Replace the following with the starter dependencies of specific modules you wish to use
implementation 'org.springframework.ai:spring-ai-openai'
}
Add dependencies for specific components
Each of the following sections in the documentation shows which dependencies you need to add to your project build system.
A scoped DNS query can use only specified network interfaces (e.g.
Ethernet or WiFi), while non-scoped can use any available interface.
More verbosely, an application that wants to resolve a name, sends a request
(either scoped or non-scoped) to a resolver (usually a DNS client
application), if the resolver does not have the answer cached, it sends a
DNS query to a particular nameserver (and this goes through one interface, so it is always “scoped”).
In your example resolver #1 “for scoped queries” can use only en0 interface (Ethernet).
One note to anyone wanting to remove the DNS, just write “empty” (without the quotes) instead of the DNS: sudo networksetup -setdnsservers <networkservice> empty